websocket communitation to another pc python

Solutions on MaxInterview for websocket communitation to another pc python by the best coders in the world

showing results for - "websocket communitation to another pc python"
Martín
06 Apr 2020
1#################################################################
2# Client:
3#!/usr/bin/env python3
4
5import sys
6from socket import socket, AF_INET, SOCK_DGRAM
7
8SERVER_IP   = '192.168.8.102'
9PORT_NUMBER = 5000
10SIZE = 1024
11print ("Test client sending packets to IP {0}, via port {1}\n".format(SERVER_IP, PORT_NUMBER))
12
13mySocket = socket( AF_INET, SOCK_DGRAM )
14myMessage = "Hello!"
15myMessage1 = ""
16i = 0
17while i < 10:
18    mySocket.sendto(myMessage.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
19    i = i + 1
20
21mySocket.sendto(myMessage1.encode('utf-8'),(SERVER_IP,PORT_NUMBER))
22
23sys.exit()
24
25
26
27#################################################################
28# Server:
29#!/usr/bin/env python3
30
31from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM
32import sys
33PORT_NUMBER = 5000
34SIZE = 1024
35
36hostName = gethostbyname( '0.0.0.0' )
37
38mySocket = socket( AF_INET, SOCK_DGRAM )
39mySocket.bind( (hostName, PORT_NUMBER) )
40
41print ("Test server listening on port {0}\n".format(PORT_NUMBER))
42
43while True:
44    (data,addr) = mySocket.recvfrom(SIZE)
45    print data
46sys.exit()