Java sockets: DataOutputStream or OutputStream?

后端 未结 3 2232
慢半拍i
慢半拍i 2021-02-07 08:11

I\'m still relatively new to sockets, and I haven\'t seen any information regarding this subject.

To write to a connected socket, you can either use

sock         


        
3条回答
  •  萌比男神i
    2021-02-07 08:16

    Use DataOutputStream if you need the extra APIs. If you don't, there is no point. But you should always wrap the socket's output stream in a BufferedOutputStream if you are doing small writes, and flush() when appropriate, i.e. before you read the socket for example.

提交回复
热议问题