• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sockets: How to receive server response in client

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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:


DataInputStream input;
try {
input = new DataInputStream(MyClient.getInputStream());
}
catch (IOException e) {
System.out.println(e);
}


Any help would be much appreciated.



- Mike
 
Mike Cunningham
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks,

Mike



________________________________________________



 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Mike Cunningham
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Cunningham:

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 ]
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably have to consider whether there are firewalls inbetween as well......
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic