Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

De-Serialize object from Socket.  RSS feed

 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making my first attempt to serialize an object to a socket and in a blocking loop at the other end deserialize it but at the moment don't have a second computer to use for testing. I would appreciate it if someone could look at this code for a thread to see if I have the right idea. The object being deserialized is a message with 5 fields. I don't expect it to be more than 100 bytes.

Thanks
Nate

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks more or less okay to me. But the way to find out for sure is to try it and see what happens.

You seem to think you need a second computer to test this. You don't. You can run the sender process and the receiver process on the same computer.

Edit: Just one comment: if line 19 fails then there's no point in continuing with lines 24 and onwards as if nothing happened. You're only going to get NullPointerExceptions.
 
Nate Lockwood
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Looks more or less okay to me. But the way to find out for sure is to try it and see what happens.

You seem to think you need a second computer to test this. You don't. You can run the sender process and the receiver process on the same computer.

Edit: Just one comment: if line 19 fails then there's no point in continuing with lines 24 and onwards as if nothing happened. You're only going to get NullPointerExceptions.


Thanks, there's more to this of course as I'll want to test this with more than one client connecting. I plan to keep track of the clients by name but the clients will all have the name "localhost". I can test for just the one thread, though..
Do I understand correctly that the queue is synchronized (line 35)?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!