socket编程的客户端和服务器为什么都要用到Thread.sleep()函数,如果不用这个函数会有什么后果呢?
比方说:clientsideSocketsocket=newSocket("IPaddressofyourserver",12345);OutputStreamout=s...
比方说:
client side
Socket socket=new Socket("IP address of your server ",12345);
OutputStream out=socket.getOutputStream();
out.write(message.getBytes());/*here, message is the information you put in EditText*/
Thread.sleep(200);
InputStream in=socket.getInputStream();
byte[] buffer=new byte[in.available()];
in.read(buffer);
msg=new String(buffer);
server side:
in = client.getInputStream();
Thread.sleep(200);
byte[] buffer=new byte[in.available()];
in.read(buffer);
OutputStream out=client.getOutputStream();
out.write(buffer); 展开
client side
Socket socket=new Socket("IP address of your server ",12345);
OutputStream out=socket.getOutputStream();
out.write(message.getBytes());/*here, message is the information you put in EditText*/
Thread.sleep(200);
InputStream in=socket.getInputStream();
byte[] buffer=new byte[in.available()];
in.read(buffer);
msg=new String(buffer);
server side:
in = client.getInputStream();
Thread.sleep(200);
byte[] buffer=new byte[in.available()];
in.read(buffer);
OutputStream out=client.getOutputStream();
out.write(buffer); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询