Sample code for 30+ languages & platforms
Java

Example: Socket.AcceptNext method

Demonstrates how to call the AcceptNext method.

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 listenSocket = new CkSocket();
    CkSocket connectedSocket = new CkSocket();

    int port = 5555;
    int backlog = 25;
    success = listenSocket.BindAndListen(port,backlog);
    if (success == false) {
        System.out.println(listenSocket.lastErrorText());
        return;
        }

    //  Accept next incoming connection
    int maxWaitMs = 200000;
    success = listenSocket.AcceptNext(maxWaitMs,connectedSocket);
    if (success == false) {
        System.out.println(listenSocket.lastErrorText());
        return;
        }

    //  ...
    //  ...

    maxWaitMs = 20000;
    connectedSocket.Close();
  }
}