This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Just as a warning... I'm new to socket programming. I have a book on the way... but I'm looking for a solution in the meantime.
I am sending a message to a server via socket 18011. That server is on a windows platform. Their VB application is acting as the socket server. It is supposed to be sending me a response. Their program is sending a response to my IP address over port 18015 ? I have tried a number of approaches. Their server supposedly tries to send a response every 10 seconds until I receive it. The code below executes but I never get the response. Is there a surefire way for me to keep that port listening on my machine for a response?
I have tried the following... but it does not seem to work:
I tried to test a server socket response based on the following code. I've added the client and server apps. The server app is noted where I am trying to send back a response to the client. Any suggestions on what I need to add to send back the response?
Originally posted by Mike Cunningham: Any suggestions on what I need to add to send back the response?
You are sending a response from the server. You are not, however, reading that response on the client. This question has more to do with Sockets and Internet Protocols so I'm going to move it to that forum.
Originally posted by J Kneeland: Wait a second, so you are saying that you contact the VB server on it's port 18011 and then it some how (disconect first?) connects back on your port 18015 ?
The VB server is from another department which is using a product from Dart.com called PowerTCP Winsock Tool. I'm connecting via Java application to a new socket using port "A" on his server. He is then supposed to be sending me a response back on port "B" to my machine. Do I need to have a socket server running on my machine to receive the response from his server or can I add code in my client to listen for the response?
I'm connecting via Java application to a new socket using port "A" on his server. He is then supposed to be sending me a response back on port "B" to my machine.
Just like J Kneeland, I am amazed that your system works that way. You will have to set up a ServerSocket to listen to port "B" on your client. If you want to learn more about networking, check out the Networking chapter of the Java Tutorial. [ August 25, 2004: Message edited by: Joe Ess ]
Are there two connection involved, or just two ports?
A TCP connection consists of two machine/port pairs. When your machine connects to the server, it uses an ephemeral port number on your machine but connects to a well known port number (18011 in this case) on the server. The ephemeral port number on your machine is machine assigned and may vary from connection to connection; you shouldn't have to worry about it, because the connection setup takes care of informing the server what it is. The server can then send responses on the same TCP connection, which is two way. If this is the way your system works, than your bug is elsewhere than the port numbers.
On the other hand, it's possible that the server application connects back using a second TCP connection. In this case, it will use an ephemeral port on the server machine and connect to a well known port on your machine (perhaps 18015 in this case?) If this is the way your system works, then yes, you need to set up a ServerSocket to listen on port 18015 on your machine.