开发者

Sending and Receiving bytes from socket connection

开发者 https://www.devze.com 2023-02-15 22:55 出处:网络
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 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

精彩评论

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