与服务器的套接字连接:java.net.UnknownHostException:无法解析主机“”:没有与主机名关联的地址

时间:2022-01-29 15:49:05

I am trying to stream an byte buffer through socket connection.

我试图通过套接字连接流式传输字节缓冲区。

Its not making connection with the server.I have added Internet & ACCESS_NETWORK_STATE permission to manifest file.

它没有与服务器建立连接。我已经为清单文件添加了Internet和ACCESS_NETWORK_STATE权限。

Here is my socket code :

这是我的套接字代码:

int port = 80;

System.out.println("Connecting to " + ServerUrl.url_audio_call + " on port " + port);
Socket client = new Socket("http://192.168.1.1/call", port);
System.out.println("Just connected to " + client.getRemoteSocketAddress()); 
OutputStream outToServer = client.getOutputStream();
DataOutputStream out = new DataOutputStream(outToServer);
out.write(bData);

LogCat error :

LogCat错误:

01-22 12:07:03.990: I/System.out(14688): Connecting to http://192.168.1.1/call on port 80
01-22 12:07:03.990: W/System.err(14688): java.net.UnknownHostException: Unable to resolve host "http://192.168.1.1/call": No address associated with hostname
01-22 12:07:03.990: W/System.err(14688):    at java.net.InetAddress.lookupHostByName(InetAddress.java:400)
01-22 12:07:03.999: W/System.err(14688):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-22 12:07:03.999: W/System.err(14688):    at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-22 12:07:03.999: W/System.err(14688):    at java.net.Socket.tryAllAddresses(Socket.java:108)
01-22 12:07:03.999: W/System.err(14688):    at java.net.Socket.<init>(Socket.java:177)
01-22 12:07:03.999: W/System.err(14688):    at java.net.Socket.<init>(Socket.java:149)
01-22 12:07:03.999: W/System.err(14688):    at com.audio_demo.Audio_Call.sendRec(Audio_Call.java:447)
01-22 12:07:03.999: W/System.err(14688):    at com.audio_demo.Audio_Call.access$0(Audio_Call.java:383)
01-22 12:07:03.999: W/System.err(14688):    at com.audio_demo.Audio_Call$2.run(Audio_Call.java:374)
01-22 12:07:03.999: W/System.err(14688):    at java.lang.Thread.run(Thread.java:856)

Can anyone help me out.Where I am going wrong.

任何人都可以帮助我。我哪里出错了。

1 个解决方案

#1


4  

"http://192.168.1.1/call" is an URL, "192.168.1.1" is an IP. so you are passing wrong argument, the program cannot understand...

“http://192.168.1.1/call”是一个URL,“192.168.1.1”是一个IP。所以你传递错误的论点,程序无法理解......

#1


4  

"http://192.168.1.1/call" is an URL, "192.168.1.1" is an IP. so you are passing wrong argument, the program cannot understand...

“http://192.168.1.1/call”是一个URL,“192.168.1.1”是一个IP。所以你传递错误的论点,程序无法理解......