Reputation: 53
What are the exceptions which generates while using functions of socket lib in Python language. I have list of exception errors, but dont know which error are for socket function. https://docs.python.org/2/library/errno.html I want to handle every error cases in TCP socket.
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
Upvotes: 4
Views: 10087
Reputation: 963
because you send many requests and when you send many requests the host will automatiquly block you i will try to fix the repeat Error Exceptions with my own script:
import socket
import sys
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = '192.168.1.26'
port = 56000
while True:
try:
s.connect((server, port))
except socket.error as e:
print "error while connecting :: %s" % e
break
while True:
try:
# Send data
message = 'This is the message. It will be repeated.'
print 'sending "%s"' % message
s.send(message)
except socket.error as e:
print "error while sending :: " + str(e)
break
thats it
Upvotes: 5