oska874
2015-07-31 14:32:15 +08:00
socket 编程好多问题。改过之后
server:
import socket
s = socket.socket()
host = socket.gethostname()
port = 1234
s.bind((host, port))
s.listen(5)
c, addr = s.accept()
while True:
request = c.recv(1024)
print "request is: ",request
print "connect by ",addr
sentence = raw_input("please enter\n")
c.sendall(sentence)
c.close()
client:
import socket
s = socket.socket()
host = socket.gethostname()
port = 1234
s.connect((host,port))
while True:
request = raw_input("say sth: ")
s.sendall(request)
reply = s.recv(1024)
print "reply is: ",reply
s.close()
ubuntu 底下试了ok