android socket 编程,用java可以实现的服务器端,现在要复制源码到android平台上,可跟客户端连不上
客户端的代码:socket=newSocket("10.10.96.163",54321);服务器的代码:ServerSocketserverSocket=newServ...
客户端的代码:socket=new Socket("10.10.96.163",54321);
服务器的代码:ServerSocket serverSocket=new ServerSocket(54321);
急,哪位高手帮忙一下,为什么啊,还有应该怎样改才行!谢谢了
其中代码入下: Thread thread = new Thread(r);
thread.start();
}
Runnable r = new Runnable() {
@Override
public void run() {
socketserver();
}
};
public void socketserver()
{
ServerSocket serverSocket=null;
try {
serverSocket=new ServerSocket(54321);
Socket client=serverSocket.accept(); try
{ BufferedReader in=new BufferedReader(new InputStreamReader(client.getInputStream()));
str=in.readLine(); //PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())),true);
in.close();
}catch(Exception ex)
} ex.printStackTrace();
}
finally
{
client.close(); }
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
我是个初学者,希望高手们指点,帮我解决一下。谢谢了 展开
服务器的代码:ServerSocket serverSocket=new ServerSocket(54321);
急,哪位高手帮忙一下,为什么啊,还有应该怎样改才行!谢谢了
其中代码入下: Thread thread = new Thread(r);
thread.start();
}
Runnable r = new Runnable() {
@Override
public void run() {
socketserver();
}
};
public void socketserver()
{
ServerSocket serverSocket=null;
try {
serverSocket=new ServerSocket(54321);
Socket client=serverSocket.accept(); try
{ BufferedReader in=new BufferedReader(new InputStreamReader(client.getInputStream()));
str=in.readLine(); //PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())),true);
in.close();
}catch(Exception ex)
} ex.printStackTrace();
}
finally
{
client.close(); }
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
我是个初学者,希望高手们指点,帮我解决一下。谢谢了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询