The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Very simple chat program hanging

This is the code. it seems to be a problem with the threads not the socket connection, when i run it it just uses all the cpu and hangs Help me please i`m loosing my mind over this coz i can`t really find something wrong with it and it is due tomorrow...

The exception says that there is no listening socket at the address
and port number you attempted to connect to.

Is the process running? Is it listening where you think it is? Are you
connecting where you think you are? Most of these things can be
diagnosed with e.g. netstat on the target machine and a network
snooping tool like tcpdump or ethereal.

Re: Very simple chat program hanging

well i know about that first set of 10 errors they are simply a set of 10 attempts to connect to a server to see if there si one running on the target machine and if not the code goes on to establish a rurver itsself so that is not a problem. i am pretty sure that the two isntances of the program (currently testing one one pc running two times) do connest to each other the problem seems to come from the threads maybe tey are in sone sort of weird deadlock (well not exactly) but i cant seem to figure it out

Hangs where? Add some println's in there to determine where it hangs to debug the flow of the code. We don't have a server to connect to, so if your program hangs beyond that point you need to give us more information, such as where it 'hangs', what the server sends, etc...

Re: Very simple chat program hanging

thanks for the edit (not familiar with the forum sry) the connection seems to play out just fine
System.out.println("CONNECTION ESTABLISHED AS CLIENT!");
System.out.println("CONNECTION ESTABLISHED AS SERVER!");
these two messages are right after the attempts to connect the two sockets together and should only display if the connection is ok and they do in their respective instances of the program so i really think its a matter of threads. otherwise it mamages to start the two threads after which netbeans hangs from lack of cpu no error code no nothing

Re: Very simple chat program hanging

well the idea is that the program can be both a client and a server it checks it there is a server on the other machine( the 10 errors) and if not opens a server socket itsself and waits for a connection but i think that that part is actually working well