Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to develop a TCP echo server, in Python?

"""
TCP echo server that converts a message
received from client into uppercase and
then sends it back to client. 
"""
from socket import *
# Port number of server
server_port = 12000
# Server using IPv4 and TCP socket
server_socket = socket(AF_INET, SOCK_STREAM)
# Bind server to port number and IP address
server_socket.bind(("127.0.0.1", server_port))
# server_socket is a welcoming socket/door
# Parameter specifies the max nb of queued requests
server_socket.listen(1)
print("The server is ready to receive msgs...")
while True:
    # TCP connection establishment phase:
    # When client knocks on the door, create a
    # connection socket dedicated to client
    connection_socket, addr = server_socket.accept()
    # Data transfer phase
    sentence = connection_socket.recv(1024).decode()
    capitilized_sentence = sentence.upper()
    connection_socket.send(capitilized_sentence.encode())
    # TCP connection termination phase
    connection_socket.close()
Comment

PREVIOUS NEXT
Code Example
Python :: check package version python 
Python :: load ui file pyqt5 
Python :: how to manually click button godot 
Python :: how to trim mp4 with moviepy 
Python :: how to know python bit version 
Python :: iterate over rows dataframe 
Python :: python detect internet connection 
Python :: how to add input box in tkinter 
Python :: how to raise a error in python 
Python :: how to count down in python using turtle graphics 
Python :: how to stop the program in python 
Python :: how to find common characters in two strings in python 
Python :: number of times a value occurs in dataframne 
Python :: how to find the neighbors of an element in matrix python 
Python :: python print to terminal with color 
Python :: seaborn styles 
Python :: create json list of object to file python 
Python :: python save figure as pdf 
Python :: python is not set from command line or npm configuration node-gyp 
Python :: token_obtain_pair check email 
Python :: pyttsx3 speech to mp3 
Python :: python bisection method 
Python :: sqlite3 like python 
Python :: find sum of values in a column that corresponds to unique vallues in another coulmn python 
Python :: how to close python with a line of code 
Python :: requirements.py for flask 
Python :: pandas get index of max value in column 
Python :: python selenium itemprop 
Python :: most occurring string in column pandas 
Python :: pyqt5 window size 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =