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); 展开
1个回答
浙江启扬智能科技有限公司
2023-06-12 广告
2023-06-12 广告
Android和ARM、Linux之间存在密切的联系。Android是一种基于Linux内核的嵌入式智能操作系统,它采用了ARM处理器作为其主要处理器架构。Android的内核和许多应用程序都是基于ARM架构编写的,包括处理器和内存管理器。...
点击进入详情页
本回答由浙江启扬智能科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询