Websocket -Kommunikation zu einem anderen PC -Python
#################################################################
# Client:
#!/usr/bin/env python3
import sys
from socket import socket, AF_INET, SOCK_DGRAM
SERVER_IP = '192.168.8.102'
PORT_NUMBER = 5000
SIZE = 1024
print ("Test client sending packets to IP {0}, via port {1}\n".format(SERVER_IP, PORT_NUMBER))
mySocket = socket( AF_INET, SOCK_DGRAM )
myMessage = "Hello!"
myMessage1 = ""
i = 0
while i < 10:
mySocket.sendto(myMessage.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
i = i + 1
mySocket.sendto(myMessage1.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
sys.exit()
#################################################################
# Server:
#!/usr/bin/env python3
from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
import sys
PORT_NUMBER = 5000
SIZE = 1024
hostName = gethostbyname( '0.0.0.0' )
mySocket = socket( AF_INET, SOCK_DGRAM )
mySocket.bind( (hostName, PORT_NUMBER) )
print ("Test server listening on port {0}\n".format(PORT_NUMBER))
while True:
(data,addr) = mySocket.recvfrom(SIZE)
print data
sys.exit()
Merwanski