Sample code for 30+ languages & platforms
Java

Receive Bytes up to a Delimiter into a BinData

See more Socket/SSL/TLS Examples

Demonstrates Socket.ReceiveUntilByteBd, which reads bytes until a delimiter byte is encountered and appends all bytes up to and including the delimiter to a BinData.

Background. The delimiter is a raw byte value from 0 through 255. This is useful for framing schemes that terminate each message with a known delimiter byte.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkSocket socket = new CkSocket();

    //  Connect to the server using TLS.
    boolean bTls = true;
    int maxWaitMs = 5000;
    success = socket.Connect("example.com",5000,bTls,maxWaitMs);
    if (success == false) {
        System.out.println(socket.lastErrorText());
        return;
        }

    //  Read bytes until the delimiter byte is encountered, appending all bytes up to and including the
    //  delimiter to a BinData.  The delimiter is a raw byte value from 0 through 255 (here the linefeed
    //  byte, decimal 10).
    CkBinData bd = new CkBinData();
    success = socket.ReceiveUntilByteBd(10,bd);
    if (success == false) {
        System.out.println(socket.lastErrorText());
        return;
        }

    System.out.println("Received " + bd.get_NumBytes() + " bytes (including the delimiter).");
  }
}