It's been a while since I did socket programming but if you setup your
socket as follows:

InetAddress localAddress = InetAddress.getLocalHost();
int localPort = 5000;
Socket sock = new Socket(destinationAddress, destinationPort, localAddress,
localPort);
System.out.println("Socket: " + sock.toString());

you can specify the local address. The method getPort() retrieve's the
socket's remote port. You should try getLocalPort() on the client to get the
socket's local port.


Justy

----- Original Message -----
From: "JavaSoft" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 31, 2001 5:55 AM
Subject: OOT:Socket Problem


Hi,
Anyone knows how in socket programming to make a client connects to a server
with specific local port ?

I mean if the server provides port 1000.. i wanna make my client connect to
the port 1000 in server side using port 5000 in client side.
I have been looking in the Socket class in the API but looks like no method
for that.

I was trying to use Socket(InetAddress address, int port, InetAddress
localAddr, int localPort) in client side. I use 5000 in the int localPort.
But when i try to print.out what port that the client using in server side
using Socket.getPort() method, i got diffrent value. Its not 5000 but others
and always changing everytime i restart the client.

Is there something that I missed ?


==
thx,
a Java Addicted

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to