• Post Reply Bookmark Topic Watch Topic
  • New Topic

send an int value over the network

 
Haritha Gorijavolu
Greenhorn
Posts: 21
Debian Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My goal is to send an int value from one computer to another. Presently, I am running the code for sending and recieving on local host alone.
The sending code is executed by the "main" thread and the recieving code is executed by the thread that was forked from the main.The child thread also listens for incoming requests by "main" thread. When it detects a request, it calls the recieving code.

Here is the sending code:



Here is the recieving code:


I am getting the following exception:

Exception in thread "Thread-0" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at com.test.Netboxbeta$reqhandler.getsize(Netboxbeta.java:99)
at com.test.Netboxbeta$reqhandler.run(Netboxbeta.java:69)
at java.lang.Thread.run(Unknown Source)

can anyone tell me why the int value is not being transfered? please help. Thanks in advance.
 
Campbell Ritchie
Marshal
Posts: 52580
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which suggests (probably) that size0 is null. You can get null after the last line has been read, but I am only certain about that for files. Not sure about sockets.

I think this question is too difficult for "beginning", so I shall move it.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get null after the last line has been read, but I am only certain about that for files. Not sure about sockets.
BufferedReader returns null when the backing Reader has no more data. It doesn't care what type of Reader it is. And since the backing Reader is an InputStreamReader that means that the backing InputStream, from the Socket, has no more data.


Haritha, I suggest you try using DataInputStream and DataOutputStream instead:

 
Haritha Gorijavolu
Greenhorn
Posts: 21
Debian Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, Mr.Spoor. The code now works fine with DataInputStream and DataOutputStream.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!