• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send objects through sockets?  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the following but the PC just hung up
Socket s = new Socket(InetAddress.getByName(null),1234);
ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
Any idea why this happens and suggestions how to overcome this problem?
 
paul wheaton
Trailboss
Posts: 22262
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have lots of ideas, but I don't know for sure.
First, where does InetAddress.getByName(null) take you?
Second, does that place have a server set up at port 1234?
Third, does that server have an Object InputStream set up?
If you're going to tinker with sockets, open a socket to a web site and hook a reader up to it. Dump what you get to the console to make sure you got the right stuff.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!