Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python how to make a server

#server
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1234))#the 1234 is the server ip that client is going to connect to.
s.listen(5)


while True:
    clientsocket, Address = s.accept()
    print(f'IP Address [{Address}] has connect to the server')#this is what the server will show when the client connect to the server.
    clientsocket.send(bytes("hi", "utf-8" ))#this is what the client will be showen.
    clientsocket.close()
#---------------------------------------------------------------
#client
#this code needs to be in a diffenet file
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((socket.gethostname(), 1234))#the 1234 is the server ip the client is connecting to.

full_msg = ''

while True:
    msg = s.recv(8)
    if len(msg) <= 0:
        break
    full_msg += msg.decode("utf-8")
    print(msg.decode("utf-8"))
Comment

how to create a python server

py -m http.server
localhost:8000
Comment

PREVIOUS NEXT
Code Example
Python :: standardscaler in machine learning 
Python :: dict godot 
Python :: convert list to array python 
Python :: the user to enter their name and display each letter in their name on a separate line python 
Python :: invoice parsing ocr python 
Python :: list of characters python 
Python :: split dataset into train, test and validation sets 
Python :: get most recent file in directory python 
Python :: plot tf model 
Python :: pandas from series to dataframe 
Python :: python windows take screenshot pil 
Python :: python namedtuple 
Python :: sum all values of a dictionary python 
Python :: how to stop running code in python 
Python :: how to access all the elements of a matrix in python using for loop 
Python :: convert number to binary python 
Python :: connect to mysql database jupyter 
Python :: create jwt token python 
Python :: remove duplicate row in df 
Python :: intersection in list 
Python :: python how to get alphabet 
Python :: pygame draw rect syntax 
Python :: A Python list exists in another list 
Python :: spacy matcher syntax 
Python :: 1052 uri solution 
Python :: load static files in django 
Python :: how to move a column in pandas dataframe 
Python :: sqrt python 
Python :: char list to string python 
Python :: get all count rows pandas 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =