2013-04-30 92 views
1

我试图发送一个整数到服务器。这是我的客户代码发送一个数字与套接字

out = new PrintWriter(_socket.getOutputStream(), true); 
    Random rand = new Random(); 
    int n = rand.nextInt(50) + 1; 
    out.println(n); 

但是服务器如何读取它?

+2

他的''''InputStream'。 – 2013-04-30 15:05:47

回答

1

改为使用DataOutputStream.writeInt()/ DataInputStream.readInt()对。