Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Socket Programming Client Side

import socket

HEADER = 64
PORT = 5050
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = "!DISCONNECT"
SERVER = "192.168.1.26"
ADDR = (SERVER, PORT)

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)

def send(msg):
    message = msg.encode(FORMAT)
    msg_length = len(message)
    send_length = str(msg_length).encode(FORMAT)
    send_length += b' ' * (HEADER - len(send_length))
    client.send(send_length)
    client.send(message)
    print(client.recv(2048).decode(FORMAT))

send("Hello World!")
input()
send("Hello Everyone!")
input()
send("Hello Tim!")

send(DISCONNECT_MESSAGE)
Comment

PREVIOUS NEXT
Code Example
Python :: convert int to hex binary in python 
Python :: pandas how to start read csv at a certain row 
Python :: how to download excel file from s3 using python 
Python :: check numpy arrays equal 
Python :: cv2 videocapture program for python 
Python :: how to sort in greatest to least python 
Python :: python ignore exception 
Python :: how to swap tuple 
Python :: selenium how to handle element not found python 
Python :: pyodbc ms access 
Python :: python code to open windows command prompt 
Python :: python change a key in a dictionary 
Python :: how to reverse a list in python 
Python :: sql alchemy engine all tables 
Python :: remove spaces from a list python 
Python :: find python path cmd 
Python :: url in form action django 
Python :: how to count number of unique values in a column python 
Python :: how to change kay bindings in pycharm 
Python :: Local to ISO 8601 with TimeZone information (Python 3): 
Python :: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 
Python :: Creating virtual environments 
Python :: python - show repeted values in a column 
Python :: dataframe print column comma separated 
Python :: Example XlsxWriter in Python 
Python :: create dictionary comprehension python 
Python :: extract month as integer python 
Python :: install nltk in python 
Python :: icon tkiner 
Python :: right angle triangle in python 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =