开发者

Sending and Receiving bytes from socket connection

I want to make a Server, that lets a Client connect through a socket connection.

The thing I can't get done is that I can not find a metho开发者_StackOverflow中文版d for sending a byte.

I only found articles and examples over sending Messages and Echoing, but that is not what I need, as the received bytes may not be visible.


To send a single byte via a connected Socket, simply get it's OutputStream and call .write() on that:

Socket s = ...;
byte b = 100;
s.getOutputStream().write(b);

For more in-depth information and examples, see the Chapter on Sockets from the Java Custom Networking Tutorial.


Socket.getInputStream() and Socket.getOutputStream() is what you are looking for. Also, take a look to this example for further info.

Regards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜