This is the server side...
Code: Select all
import socket
from threading import *
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "localhost"
port = 8000
print (host)
print (port)
serversocket.bind((host, port))
class client(Thread):
def __init__(self, socket, address):
Thread.__init__(self)
self.sock = socket
self.addr = address
self.start()
def run(self):
while 1:
print('Client sent:', self.sock.recv(1024).decode())
self.sock.send(b'Oi you sent something to me')
serversocket.listen(5)
print ('server started and listening')
while 1:
clientsocket, address = serversocket.accept()
client(clientsocket, address)Code: Select all
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host ="192.168.x.x"
port =8000
s.connect((host,port))
def ts(str):
s.send('e'.encode())
data = ''
data = s.recv(1024).decode()
print (data)
while 2:
r = input('enter')
ts(s)
s.close ()socket.error: [Errno 10060] A connection attempt failed, etc, etc.
So 2 questions...
First, what's wrong with the code(s) that the 2 can't communicate?
Secondly, how can I have the server doing other stuff while waiting for the client to send some data. This is going to be sending commands to a quadcopter, very little packet size and not too often but the Pi (server) needs to be taking care of other things.
Or is there a better alternative?
Dave.
Edit: Don't think this is relevant but at the moment this is running on 2 Windows laptops.