Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket - Packets separated once send to server

Tags:

java

sockets

I'm trying to send sockets to a server using Java:

_socket   = new Socket(host, port);
_writer   = new DataOutputStream(_socket.getOutputStream());

public void send(String data){
    _writer.writeBytes( data );
    _writer.flush();
}

I want to send data as a same Packet, and sometimes it's divide into multiples one. I don't know if it's clear enough, I'm missing some vocabulary.

If I send:

"0123456789abcdefghijklmnopqrstuvwxyz"

The server can possibly receive the data into 3 packets :

  1. "0123456"
  2. "789abcdefghijklmno"
  3. "pqrstuvwxyz"

Is there a way to don't separate the data you send into multiple packets ?


BufferedOutputStream seems to fix the problem.

like image 684
Vincent Thibault Avatar asked Mar 20 '26 11:03

Vincent Thibault


1 Answers

BufferedOutputStream seems to fix the problem.

like image 99
Vincent Thibault Avatar answered Mar 22 '26 00:03

Vincent Thibault



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!