• Post Reply Bookmark Topic Watch Topic
  • New Topic

IOException firing up when doing basic socket reading/writing.  RSS feed

 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize in advance if this isn't really a Java question, I still don't know what the problem is.

I'm using the code from Java's online tutorials HERE

I honestly don't know what to use as the host name (first parameter of the Socket constructor), I tried using "127.0.0.1" and I keep getting an IOException.

Do I need to somehow "set up" my computer to be a local host? I'm assuming that there's no problem there since UnknownHostException isn't firing up, so what could be the problem?

Thank you for your time.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"127.0.0.1" or "localhost" should work, but you should ofcourse make sure that you have a server running on your computer that listens to the port you are connecting to - if you haven't, your client program ofcourse can't connect.

Have you already read the next page of the tutorial: Writing the Server Side of a Socket?
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I'm using the well-known "Echo" port, I assumed I wouldn't need to set-up a server for that, am I mistaken?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because a port is "well-known" doesn't mean that there is a service listening on that port.
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I would have been stuck there forever

I ran the next example and it worked just fine. Really appreciate it, I've been stuck on this for quiet a while.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!