java与ios tcp通讯
try {
ServerSocket ss = new ServerSocket(10000);
while (true) {
System.out.println("1000端口监听");
Socket s = ss.accept();// 开启连接
System.out.println("客户端IP:"+s.getInetAddress());
System.out.println("客户端IP:"+s.getPort());
//读取套接字并存放在buffer里
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
//解析buffer里的字节
String str = br.readLine();
System.out.println("str=>"+str);
InputStream is = s.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len;
byte[] b = new byte[1024];
while ((len = is.read(b)) != -1) {
System.out.println("len => " + len);
baos.write(b, 0, len);
}
byte[] data = baos.toByteArray();
//返回客户端信息
PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
pw.println("我是服务器,我收到了你发来的消息=>"+len);
System.out.println("客户端发来的消息:" + new String(data));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
可以接受到IOS客户端的数据,但是返回不了给客户端数据,求解各路大神!! java ios 通讯 --------------------编程问答-------------------- PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
pw.println("我是服务器,我收到了你发来的消息=>"+len);
pw.flush(); --------------------编程问答-------------------- 还是没用!客户端收不到我返回的数据
补充:Java , Java相关