11-26-2010 02:03 PM
Hi All,
I've following problem:
I'm trying to develop server application on the device side, which will be listening for the incoming connection on TCP. I'm creating ServerSocketConnection object, listening for the connection, after connection request, I'm using accepted socket, and closing listening socket, because this socket don't needed for me anymore. But if session is closed, I'm trying to open listening socket again, and it cause IOException: Port in use. I've written small piece of code, to test this issue, and it constantly throws an exception:
try{
ServerSocketConnection connection = (ServerSocketConnection)Connector.open(socket://:5 555;interface=wifi, Connector.READ_WRITE, false);
StreamConnection acceptedConnection = (StreamConnection)connection.acceptAndOpen();
if (null != acceptedConnection) { acceptedConnection.close(); connection.close();
}
//Just for test, trying to open it again
connection = (ServerSocketConnection)Connector.open(socket://:5 555;interface=wifi, Connector.READ_WRITE, false);
}
catch(IOException e) {
//ERROR
}
Does it mean that ServerSocketConnection.close is not synchronous? Or I'm doing something wrong?
I understand that one of the solutions it to open listening socket once, and keep it opened, but I'm interested in root cause of problem.
If somebody know the answer, or had the similar issues - I will be very thankful for any help.
Environment:
JRE 6.0.0
Device - Torch 9800
6.0 Bundle 695 (v. 6.0.0.246. Platform 6.4.0.105)
11-07-2011 12:15 PM - edited 11-07-2011 12:16 PM
I receive the same issue with socket and udp connections.
And my process for closing is close inputstream, close outputstream, close connection:
// Clear out this connection
if (SocketInput != null)
{
try
{
SocketInput.close();
}
catch (Throwable t)
{
// Do nothing
}
}
if (SocketOutput != null)
{
try
{
SocketOutput.close();
}
catch (Throwable t)
{
// Do nothing
}
}
if (Connection != null)
{
try
{
Connection.close();
}
catch (Throwable t)
{
// Do Nothing
}
}
Connection = null;