[Tutor] Socket question.
Alan Gauld
alan.gauld at btinternet.com
Wed May 16 23:12:41 CEST 2007
"Dude, WHOA!" <sxkorean at gmail.com> wrote
> kinda thing. The problem is that the client I wrote doesn't receive
> data and display it, and it also only executes single word commands.
> Server side:
> #!/usr/bin/env python
> import socket
> from subprocess import *
> IP = 'localhost'
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> sock.bind((IP, 1234))
You are using localhost so it will only work with the client on
the same PC and using port 1234.
> Client:
> IP = raw_input('IP: ')
> PORT = input('PORT: ')
So there is no point in asking the user, it has to be
IP = 127.0.0.1
PORT = 1234
Anything else will fail.
You can look at the Network programming topic on my
tutorial for some similar examples if you like.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list