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.

unable to get server socket in client thread

Hi ,
I am developing client server based application.
After reading the data from the server clients open the thread and starts it in the thread im unable to get data from server when i do it says socket is already closed even the server program is running.
Following is my server THREAD code : which send data to client :
[code]
ServerSocket main = ser.Socket();
while(true){
clientsocket = main.accept();

[/code/
following the the client when receives data from server till this line before "TURING CAM ON" and than it donot receive data , it opens a thread and there client need to receive abc from server. Following is the client class :

getting closed server socket in client thread

Hi ,
I am developing client server based application.
After reading the data from the server clients open the thread and starts it in the thread im unable to get data from server when i do it says socket is already closed even the server program is running.
Following is my server THREAD code : which send data to client :

following the the client when receives data from server till this line before "TURING CAM ON" and than it donot receive data , it opens a thread and there client need to receive abc from server. Following is the client class :

Re: unable to get server socket in client thread

Possible duplicate. merging.

@OP: please edit your post to make it readable. Put [code] at the start of a section of code and [/code] at the end: that wy the code will be formatted. You may have to check that the indentation is correct.

Re: unable to get server socket in client thread

Hi ,
I am developing client server based application.
After reading the data from the server clients open the thread and starts it in the thread im unable to get data from server when i do it says socket is already closed even the server program is running.
Following is my server THREAD code : which send data to client :

following the the client when receives data from server till this line before "TURING CAM ON" and than it donot receive data , it opens a thread and there client need to receive abc from server. Following is the client class :

Re: getting closed server socket in client thread

Originally Posted by Norm

Can you make a small complete program the compiles, executes and shows the problem.
It is not possible to compile and execute what you have posted for testing.

in first code : there is server thread waiting for client to connect. the second part is client main class which connects with ser and do write name , server update the clients name and send all the client name to client as String[] after receiving clientnames array from server for further receiving client opens the thread as third code snippet but in the
BufferedReader rdr= new BufferedReader( new InputStreamReader(serverSocket.getInputStream()));

it says server socket is closed on the other hand server is writing abc there which should be received from this thread.
SHould i post all related code here ?