Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Client Socket  RSS feed

 
Donald Rovas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm having trouble creating a simple client socket that sends and receives a message. Here's the code:

I've determined that it hangs on the in.read() line. I tried closing the output stream after I write to it but that closes the socket - I get an exception:

java.io.IOException: Socket Closed

By the way I sucessfully wrote a client using the URLConnection class; however, I want to be able to send HTTP and SOAP messages explicitly.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Donald,
The main problem here is that you have to flush the stream before it is sent. You also had a few other problems that I took to liberty to repair:

Hope this helps,
Michael Morris
 
Donald Rovas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael,
Now it works with msg="GET" and a call to out.flush(). Could you tell me why it doesn't work when msg="GET / HTTP/1.1" - I copied this directly from the first line that IE sends to the server when requesting the default document?(I have a simple webserver that reports what is sent)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!