我正在自学Python网络,我回想起当我自学线程时,我遇到了这个页面,所以我复制了脚本,为Python 3.1.1更新了它们并运行它们.他们工作得很好.
然后我做了一些修改.我的目标是做一些简单的事情:
这是服务器:
import pickle
import socket
import threading
class ClientThread(threading.Thread):
def __init__(self, channel, details):
self.channel = channel
self.details = details
threading.Thread.__init__ ( self )
def run(self):
print('Received connection:', self.details[0])
request = self.channel.recv(1024)
response = pickle.dumps(pickle.loads(request) * 2)
self.channel.send(response)
self.channel.close()
print('Closed connection:', self.details [ 0 ])
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 2727))
server.listen(5)
while True:
channel, details = server.accept()
ClientThread(channel, details).start()
Run Code Online (Sandbox Code Playgroud)
这是客户:
import pickle
import socket
import threading
class ConnectionThread(threading.Thread):
def run(self):
client = …Run Code Online (Sandbox Code Playgroud) 我正在调试一个过去有效的简单程序.我已经挑出了发生错误的指令,但我无法弄清楚是什么触发它.我已经阅读了与WinError 10061相关的所有问题,但我没有看到明确的答案
urllib.request.urlopen('http://www.wikipedia.org/')
Traceback (most recent call last):
File "C:\Python33\lib\urllib\request.py", line 1248, in do_open h.request(req.get_method(), req.selector, req.data, headers)
File "C:\Python33\lib\http\client.py", line 1061, in request self._send_request(method, url, body, headers)
File "C:\Python33\lib\http\client.py", line 1099, in _send_request self.endheaders(body)
File "C:\Python33\lib\http\client.py", line 1057, in endheaders self._send_output(message_body)
File "C:\Python33\lib\http\client.py", line 902, in _send_output self.send(msg)
File "C:\Python33\lib\http\client.py", line 840, in send self.connect()
File "C:\Python33\lib\http\client.py", line 818, in connect self.timeout, self.source_address)
File "C:\Python33\lib\socket.py", line 435, in create_connection raise err
File "C:\Python33\lib\socket.py", line 426, in create_connection sock.connect(sa)
ConnectionRefusedError: …Run Code Online (Sandbox Code Playgroud)