javasocketsconnectexception

Socket Programming ConnectException


Im trying a programming to build an app to send and receive messages it also uses everything is set and working except that the Connect Exception: it is constantly saying connection timed out... i have this code on working

socket s = new socket(destination,8888);

then furthur using the outputstream at firstly initiating end and then

socket d= new socket (sender,8888);

and then input stream at the receiving end and both system are well connect with the code

ServerSocket ss = new ServerSocket(8888);
Socket b= new Socket();
b=ss.accept();

what could possibly be wrong??


Solution

  • Alot of chat programs spawn a new Thread, when the connection has been made, have you considered that? if you just do

       ServerSocket ss = new ServerSocket(8888);
       Socket b= new Socket();
       b=ss.accept();
    

    And you program ends after this line, it could cause a timeout exception because the client instantly lost the connection, when the server closed down.

    if this is completely retarded, please provide more code, its hard to make assumptions about your implementation.