fix receive
This commit is contained in:
parent
5074e6ef54
commit
c7fa00906d
2 changed files with 17 additions and 9 deletions
|
@ -8,21 +8,27 @@ s.bind((host,port))
|
|||
s.listen(1) # Number of connections
|
||||
s.setblocking(False)
|
||||
|
||||
|
||||
client = None
|
||||
while True:
|
||||
try:
|
||||
client, address = s.accept()
|
||||
print("Connected to", address)
|
||||
|
||||
|
||||
data = client.recv( 1024 ).decode( 'utf-8' )
|
||||
splitdata=data.split(",")
|
||||
|
||||
print("Received :", repr(data))
|
||||
print(splitdata)
|
||||
except socket.error:
|
||||
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()
|
|
@ -1,14 +1,16 @@
|
|||
import socket
|
||||
|
||||
import time
|
||||
|
||||
TCP_IP = '127.0.0.1'
|
||||
TCP_PORT = 30002
|
||||
|
||||
BUFFER_SIZE = 1024
|
||||
message = "12.3,20.15"
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((TCP_IP, TCP_PORT))
|
||||
|
||||
|
||||
time.sleep(1)
|
||||
s.send(message.encode('utf-8'))
|
||||
|
||||
s.close()
|
||||
|
|
Loading…
Reference in a new issue