Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

websocket communitation to another 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}
".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}
".format(PORT_NUMBER))

while True:
    (data,addr) = mySocket.recvfrom(SIZE)
    print data
sys.exit()
Comment

PREVIOUS NEXT
Code Example
Python :: Python Root finding code 
Python :: IPython default setup 
Python :: attribute error rest framework 
Python :: screen.blit() arguments 
Python :: rounding with .2g gives strange results 
Python :: how to update sheety 
Python :: django how to create superuser if does not exists on migration 
Python :: where are dictd dictionaries 
Python :: print a commans in python 
Python :: opencv houghlines only horizontal 
Python :: "json" is not defined 
Python :: jupyter notebook save as python script without terminal prompts line numbers 
Python :: reverse row order padnas 
Python :: pandas data frame from part of excel openpyxl 
Python :: eager tensor to numpy 
Python :: Value Error handling 
Python :: python empty array length n grepper 
Python :: jupyter early exit cell 
Python :: Select a Column in pandas data Frame Using Brackets 
Python :: how do you change a class variable in python 
Python :: python get all keys in dict having value in range 
Python :: google popup not opening 
Python :: if elif ladder in one line in python 
Python :: best python library to download files 
Python :: how to get each word in a string 
Python :: box plot seaborn advance python 
Python :: palindrome program in python 
Python :: handling files in django 
Python :: Create New Entry Into Table Django 
Python :: python convert docx to pdf linux 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =