1
2a OP 服务器代码如下:
import socket s = socket.socket() host = socket.gethostname() port = 1234 s.bind((host, port)) s.listen(5) while True: c, addr = s.accept() request = c.recv(1024) print "request is: ",request print "connect by ",addr sentence = raw_input("please enter\n") c.sendall(sentence) c.close() |
2
aheadlead 2015-07-31 13:55:36 +08:00 via iPhone
妹子…
|
3
aheadlead 2015-07-31 13:57:23 +08:00 via iPhone
错误信息请贴上来…
|
4
2a OP Traceback (most recent call last):
File "<stdin>", line 2, in <module> File "C:\Python27\lib\socket.py", line 224, in meth return getattr(self._sock,name)(*args) File "C:\Python27\lib\socket.py", line 170, in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: [Errno 9] Bad file descriptor |
7
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 |
8
2a OP |
10
wkdhf233 2015-07-31 15:02:15 +08:00 1
你把客户端的s = socket.socket()丢循环外边,第一轮通信完毕都close了
第二轮还s.connect((host,port)) 个条毛。。s都没有了。。 |