1
在Python语言中使用套接字库函数时产生的异常是什么? 我有异常错误的列表,但不知道哪个错误是为套接字函数。 https://docs.python.org/2/library/errno.html 我想处理TCP套接字中的每个错误情况。套接字python中的异常列表
import socket
import sys
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('192.168.1.26', 56000)
while True:
try:
sock.connect(server_address)
break
except socket.error as e:
print "error while connecting ::%s",e
while True:
try:
# Send data
message = 'This is the message. It will be repeated.'
print >>sys.stderr, 'sending "%s"' % message
sock.sendall(message)
except socket.error as e:
print "error while sending ::%s",e
套接字错误在https://docs.python.org/2/library/socket.html?#socket.error –