fix receive

This commit is contained in:
Philipp Kramer 2022-05-31 15:26:53 +02:00
parent 5074e6ef54
commit c7fa00906d
2 changed files with 17 additions and 9 deletions

View file

@ -8,21 +8,27 @@ s.bind((host,port))
s.listen(1) # Number of connections s.listen(1) # Number of connections
s.setblocking(False) s.setblocking(False)
client = None
while True: while True:
try: try:
client, address = s.accept() client, address = s.accept()
print("Connected to", address) print("Connected to", address)
data = client.recv( 1024 ).decode( 'utf-8' )
splitdata=data.split(",")
print("Received :", repr(data))
print(splitdata)
except socket.error: except socket.error:
pass pass
if client is not None:
try:
data = client.recv( 1024 ).decode( 'utf-8' )
if data:
splitdata=data.split(",")
print("Received :", repr(data))
print(splitdata)
except socket.error:
pass
s.close() s.close()

View file

@ -1,14 +1,16 @@
import socket import socket
import time
TCP_IP = '127.0.0.1' TCP_IP = '127.0.0.1'
TCP_PORT = 30002 TCP_PORT = 30002
BUFFER_SIZE = 1024
message = "12.3,20.15" message = "12.3,20.15"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT)) s.connect((TCP_IP, TCP_PORT))
time.sleep(1)
s.send(message.encode('utf-8')) s.send(message.encode('utf-8'))
s.close() s.close()