This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes Unable to send data over an established TCP connection in Java Socket programming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Unable to send data over an established TCP connection in Java Socket programming" Watch "Unable to send data over an established TCP connection in Java Socket programming" New topic
Author

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

suraj tripathi
Greenhorn

Joined: Feb 09, 2009
Posts: 8
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

You're trying to open a socket on a port that is already bound to another socket.
suraj tripathi
Greenhorn

Joined: Feb 09, 2009
Posts: 8
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Feb 09, 2009
Posts: 8
Thanks Jeff, I will keep those suggestions in mind while posting questions in future and yes my issue is resolved.

Thanks again for replying.
 
Consider Paul's rocket mass heater.
 
subject: Unable to send data over an established TCP connection in Java Socket programming
 
Similar Threads
Problem with simple chat app
Implementing java server
sending xml over tcp/ip
TCP socket ip address
WS Startup: NET_Bind (in depth, however).