(Java) Example: Socket.AcceptNext method
Demonstrates how to call the AcceptNext method. Note: This example requires Chilkat v11.0.0 or greater.
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[])
{
CkSocket listenSocket = new CkSocket();
CkSocket connectedSocket = new CkSocket();
int port = 5555;
int backlog = 25;
boolean 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();
}
}
|