I am trying to write a small python program that just sends data out over a port socket. I can get it to work when there is a server that is listening, but I can't get it to work when there is nothing there. I've tried searching but haven't found anything that will work without a receiving server.
I am basically looking for a way that will attempt to connect, if it fails, wait X and try again.
Anyone have any suggestions or examples they can share?
This is what I have so far.....
And this is what I'm getting in return.
I am basically looking for a way that will attempt to connect, if it fails, wait X and try again.
Anyone have any suggestions or examples they can share?
This is what I have so far.....
Quote:import socket
import time
import string
host = '192.168.1.11' #socket.gethostname()
port = 9999
BUFFER_SIZE = 2000
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def testConnection(host, port, socket):
connected = False
while connected == False:
try:
socket.connect((host, port))
connected = True
socket.send("Hello")
except Exception as e:
print ("Exception is %s" % (e))
time.sleep(2)
connected = False
testConnection(host, port, socket)
And this is what I'm getting in return.
Quote:Exception is [Errno 61] Connection refused
Exception is [Errno 22] Invalid argument