|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Socket reading in defined thread Hi I am creating a Client application and have come through a problem in the code. I think the problem is concerned to reading the socket in a thread, which I used for better efficiency. When i start the client application a message is sent to the server application and the server application should send a message in reply to the client. I have thrown an exception with a pointer, the code is below Code: while ((response = socketReader.readLine()) != null) // <- an exception is thrown here System.out.println(response); // and subsequent running is stopped! |
#2
| |||
| |||
Re: Socket reading in defined thread Hello You have not posted the code, it would be better to identify the problem if the code is present. Ok, forget it what exception is the stack trace is giving. Please paste the exception in the next post so that we can tell you what is the problem. Any more problem do post again. |
#3
| |||
| |||
Re: Socket reading in defined thread Hi Sorry for not posting the code. The code is too big so I am posting the error reported by the stack trace. Code: OutputHandler, wakeup and die! java.net.SocketException: socket closed at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) at sun.nio.cs.StreamDecoder.implRead(Unknown Source) at sun.nio.cs.StreamDecoder.read(Unknown Source) at java.io.InputStreamReader.read(Unknown Source) at java.io.BufferedReader.fill(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at vyuka.Net2Output.run(Client.java:16) |
#4
| |||
| |||
Re: Socket reading in defined thread Hello I think the socket is getting closed before it has finished reading the line. I am posting you a sample program. just go through it and see if it helps you. Code: class net2op extends Thread { BufferedReader sr; public net2op(BufferedReader sr) { this.sr = sr; } public void run() { try { String response; while ((response = sr.readLine()) != null) System.out.println(response); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } |
![]() |
|
Tags: internet, java, programming language, socket |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Does LGA1155 socket core i5 processor support MSI motherboard LGA 1366 socket | Firoja | Motherboard Processor & RAM | 6 | 22-07-2011 10:24 PM |
Synchronize a producer thread and a consumer thread in C# | Ayuka | Software Development | 6 | 10-11-2010 04:04 AM |
What is socket and server socket in java? | Truster | Software Development | 5 | 01-02-2010 02:08 PM |
Winsock Socket error 10048 socket bind | Theophilus | Operating Systems | 4 | 16-02-2009 08:07 PM |