• Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket data read problem !!  RSS feed

 
Karthik Simili
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with a socket-based application which I am writing for a module in my project
I created a client socket to connected to a remote server and port. The remote server sends data to a different ip address and port instead of my connection. What I mean to say is that I get the data on a different connection !!
Can anybody throw light on how to capture the data coming on a different connection from my thread of control ???
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The remote server cannot 'send' data to a different socket unless there is a ServerSocket present to 'receive'.
Or do you mean that the serve program tries to connect to an address which is different than the one you expected?
Is the protocol you are working with one that requires two sockets? Like FTP or HTTPS? Is the IP address that the remote server tries to connect to the one you expect? What port is the remote server trying to connect to?
 
Karthik Simili
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a listener program on my machine which listens to requests on port 5056. I also have a client program which connects to a remote server running on port 3002(say)
I connect to the remote server using my client program and see the output on the listener program which is running on port 5056(serversocket)
Is there a way by which I can configure a socket to receive data on a different port on my machine ???
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still confused about what you are trying to ask. First you said it was a different IP address. Now you say it's a different program. AFAIK, there is no way to share a socket in Java between two different programs. Or do you mean that the client program connects to 3002, and you want to change the 3002 to something else?
If you want to set up a server to a specific port, that's what a ServerSocket is for. You would use a ServerSocket to configure a socket to receive data at a specific port. You would just do something like:
ServerSocket ss = new ServerSocket( 3003);
Socket s = ss.accept();
But you must already know this.
If you are trying to use a specific port on the client side, there is a Socket constructor that lets you specify the local port. But that's not guaranteed to work, because the port may already be in use. Client sockets don't usually specify the local port.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!