Sockets - how to nominate local port number?
Uwe Hoffmann
qual at epost.de
Sat Jan 26 18:29:05 EST 2002
Hi!
djmitchell wrote:
> Hello group,
>
> For a particular sockets application I'm working on, I need to be able to
> specify both the port number on the remote machine, *and* the port number
> on the local machine.
> Thanks in advance for any pointers
simply extend the example from
http://www.python.org/doc/2.1.2/lib/socket-example.html
in the following way
# Echo client program
import socket
HOST = 'localhost' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#################################################################
YOUR_CLIENT_PORT_NUMBER=50008
s.bind((HOST, YOUR_CLIENT_PORT_NUMBER))
#################################################################
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', `data`
>
> Dave Mitchell
>
greetings
uwe
More information about the Python-list
mailing list