我使用GCDAsyncSocket创建iOS服务器,客户端使用Java语言创建。当我以NSDAta的形式发送数据时,它可以被SocketTester(用于测试客户端连接的应用程序)读取,但它不能在java端完全读取。如何读NSData到客户端在java中制作
static void recorderServerClient() throws IOException{
int port =9892;
clientSocket = new Socket("localhost", port);
System.out.print("Connected to localhost"+port);
while (true){
InputStream inputStream = clientSocket.getInputStream();
try {
Thread.sleep(3000);
}
catch (InterruptedException e) {
e.printStackTrace();
}/*fetch data with help of output stream and write it with help of PrintWriter */
PrintWriter printWriterObj = new PrintWriter(clientSocket.getOutputStream());
printWriterObj.println();
printWriterObj.flush();
/*created an array for now static and assign some memory */ byte[] buffer = new byte[1000000];
int read;
while((read = inputStream.read(buffer)) != -1) {
String output = new String(buffer, 0, read);
System.out.print(output);
System.out.flush();
}
}
*/
}
我想要得到的数据长度通过IOS发送server.and创建缓冲区accordingly.Can任何一个可以帮助我吗?
你看到了什么问题?看起来你缺少Socket.accept()调用? –
我无法通过java的readInt方法读取数据长度。 – Ruby