Socket send and receive byte array

后端 未结 4 1780
名媛妹妹
名媛妹妹 2020-12-05 04:44

In server, I have send a byte array to client through Java socket

byte[] message = ... ;

DataOutputStream dout = new DataOutputStream(client.getOutputStream         


        
4条回答
  •  星月不相逢
    2020-12-05 05:24

    First, do not use DataOutputStream unless it’s really necessary. Second:

    Socket socket = new Socket("host", port);
    OutputStream socketOutputStream = socket.getOutputStream();
    socketOutputStream.write(message);
    

    Of course this lacks any error checking but this should get you going. The JDK API Javadoc is your friend and can help you a lot.

提交回复
热议问题