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 :: Python basic discord bot 
Python :: how to find unique sublist in list in python 
Python :: function in python 
Python :: remove all parentheses from string python 
Python :: pandas difference between two dataframes 
Python :: 2d arrays with rows and columns 
Python :: How Generate random number in python 
Python :: Django rest framework update or delete 
Python :: python type checking 
Python :: datetime to unix timestamp python 
Python :: how many numbers greater than 100 using pytho 
Python :: how to exit a function python 
Python :: python increment filename by 1 
Python :: python online practice test 
Python :: how to remove last 2 rows in a dataframe 
Python :: count number of element in list 
Python :: pandas count occurrences of certain value in row 
Python :: django httpresponse 
Python :: append to list in dict python 
Python :: find the sitepckages for anaconda 
Python :: sns boxplot ylabelsize 
Python :: Python Tuples Tuples allow duplicate values 
Python :: instalar sympy en thonny 
Python :: Shuffle the data before GridSearchCV 
Python :: replace() python 
Python :: multiple categories on distplot 
Python :: python using strip trim white sapce 
Python :: python switch case 
Python :: Python Global in Nested Functions 
Python :: You will be provided a file path for input I, a file path for output O, a string S, and a string T. 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =