I've got a problem with a TCP Server script... I just want to receive x y coordinates in order to make my 3D objects moves.
I've made it on a thread, but my client can't connect to it. It seems to be a problem on the socket creation:
Here is the code of the script:
Code: Select all
from socket import *
import threading
import time
myHost = "localhost"
myPort = 4242
print("Creating socket ...")
s = socket(AF_INET, SOCK_STREAM)
print("Binding socket ...")
s.bind((myHost, myPort))
print("Now listening ...")
s.listen(1)
class myThread(threading.Thread):
def __init__(self, name=None):
threading.Thread.__init__(self, target=self.run, name=name, args=())
self.run()
def run(self):
print("Thread ready")
while 1:
connection, address = s.accept()
print("Connection accepted ...")
while 1:
print("recv")
data = connection.recv(1024)
print ("data: ")
print data
if not data:
print("stop connection")
connection.close()
break
print("Threading ...")
t = myThread("server")
print("Script ended")