Technical information

Standard Classes Deviations
5-18 G24 KJAVA User’s Guide July 15, 2008
while (true) {
int len = is.read(ReceiveData);
if (len > -1) {
//receive data
System.out.println("Receive data - " + new
String(ReceiveData) + "\n");
System.out.println("Number of bytes - " + len +
"\n");
} else if (len == -1) {
//connection with client has been broken.
openConnection(getAppProperty("PORT"));
}
}
} catch (IOException e) {
...
}
}
private void openConnection(String port) {
try {
//create ServerSocketConnection instance
scn = (ServerSocketConnection) Connector.open("socket://:" + port);
//wait for client connection.
sc = (SocketConnection) scn.acceptAndOpen();
sc.setSocketOption(SocketConnection.LINGER, 5);
} catch (IOException e) {
//cannot open connection
...
}
}
}
Note: In order to open more sockets in parallel, use another TcpConnection thread.