Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to send data over an established TCP connection in Java Socket programming

 
suraj tripathi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am developing an Echoer program in which the client and the server side are inside the same Java file (but inside different classes+main class separate). So basically there is a single (.java) file.
I want to transfer a short message over an already established TCP connection, to be more precise, I have already connected the client using Socket(ip, portnumber) to the Server (ServerSocket(portnumber)). However, now after linking the client to the server, in some other part of the code, I want to send a message (say, "hello") using the same connection, but I am unable to do so. I am getting an error saying, "Address already in use (Java.net.BindException)"

Please help,

Thanking you in anticipation,
Sanat
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're trying to open a socket on a port that is already bound to another socket.
 
suraj tripathi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeff for replying.

Initially I was trying to do the same thing that you mentioned, however, later I understood and now I am able to send messages over the already connected Sockets by using the connected Socket's object.

I hope my sentence is clear.

Can you give me a feedback, I wanted to know whether I explain my question clearly or not? if not, then how may I improve on them.

Thanks again
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but I don't really understand what problem you're having, or even whether you're still having it or have got it resolved. All I know is you're having some socket communication difficulties.

If you still need help, please provide an SSCCE(←click) that demonstrates your socket problems but has no extra, unrelated code. Describe precisely exactly what's happening. If there's an error message, copy/paste the exact, complete error message and indicate clearly which line is causing it.
 
suraj tripathi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeff, I will keep those suggestions in mind while posting questions in future and yes my issue is resolved.

Thanks again for replying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic