Home Bug Reports

Socket binding problem

Hi,

I've encountered two small problems. Both problems came out in java implementation of Ice. The first one appeared when I've written unit test for the server I began to implement. I wrote sequence of unit tests, which every one was builed like this:

--========= Initialization part
server initialization
client initialization

test some functionality

--========= Release part
client deinitialization
server deinitialization

For both - server and client I used shutdown and destroy methods. For server I used also deactivate adapter created by me. First unit test passed without any problems, problems appeared when began second unit test. The initialization of the server failed, because of the socket was still binded to the interface. The problem encountered on the windows XP platform, I used JDK 5.0. Below I put the stack trace, printed by the second unit test

[ Network: attempting to bind to tcp socket 127.0.0.1:5555 ]
Ice.SyscallException
error = 0
at IceInternal.IncomingConnectionFactory.<init>(IncomingConnectionFactory.java:460)
at Ice.ObjectAdapterI.<init>(ObjectAdapterI.java:829)
at IceInternal.ObjectAdapterFactory.createObjectAdapter(ObjectAdapterFactory.java:130)
at Ice.CommunicatorI.createObjectAdapterWithEndpoints(CommunicatorI.java:53)
at Ice.CommunicatorI.createObjectAdapter(CommunicatorI.java:47)
at dist.dj.server.RequestListener.run(RequestListener.java:37)
at dist.dj.util.pool.ThreadPool$PooledThread.run(ThreadPool.java:63)
Caused by: Ice.SocketException
error = 0
at IceInternal.Network.doBind(Network.java:211)
at IceInternal.TcpAcceptor.<init>(TcpAcceptor.java:128)
at IceInternal.TcpEndpointI.acceptor(TcpEndpointI.java:369)
at IceInternal.IncomingConnectionFactory.<init>(IncomingConnectionFactory.java:409)
... 6 more
Caused by: java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:52)
at IceInternal.Network.doBind(Network.java:205)
... 9 more

The second problem is the content of an exception class generated by the slice2java tool. It's small but annoying :] It generates warning in the Eclipse IDE. Below I put an example of part of method.


public class ClientNotLogged extends Ice.UserException
{
[...]
public void
__read(IceInternal.BasicStream __is, boolean __rid)
{
if(__rid)
{
String myId = __is.readString(); <-- I suppose, that is for skipping part of the data packet
}
__is.startReadSlice();
message = __is.readString();
__is.endReadSlice();
}

[...]
}

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    For the first problem, when a socket is closed, the port number is not always immediately released by the operating system. That's why you get the "Address already in use" exception. If you investigate the socket, you will see that it is in TIME_WAIT state. For more information on this, see the last paragraph of this FAQ.

    We will look into the second problem. Thanks for reporting this.
Sign In or Register to comment.