Java Socket Programming

前端 未结 6 1781
孤街浪徒
孤街浪徒 2020-12-15 02:02

I am building a simple client/server application using java sockets and experimenting with the ObjectOutputStream etc.

I have been following the tutorial at this url

6条回答
  •  死守一世寂寞
    2020-12-15 02:47

    It's better to open an outputStream because an output stream doesn't block. Then, you have the input stream that waits for a Stream. After all the streams, you write to the stream and flush it - outputStream.flush() to send the bytes of data. You'll also need a method on the other end to read the input, whether it's simply inputStream.read() which reads every byte as an integer for a char, or by using a BufferedReader or Scanner. I've used almost all methods possible, but the most effective method for sending is outputStream.write(String) which writes a sequence of chars as bytes into the stream and reading inputStream.read() reads a single char. I hope this helps.

提交回复
热议问题