Socket Programming in Python Sockets and the socket API are used to send messages across a network. They provide a form of inter process communication. The network can be a logical, local network to the computer, or one that’s physically connected to an external network, with its own connections to other networks. Echo Server #!/usr/bin/env python3 import socket HOST = '127.0.0.1' # Standard loopback interface address (localhost) PORT = 65432 # Port to listen on (non-privileged ports are > 1023) with socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) as s : s . bind (( HOST , PORT )) # associating with specific network interface and port number s . listen () # listening for incoming connections conn , addr = s . accept () # accepting the connections with conn : print ( 'Connected by' , addr ) while True : data = conn . recv ( 1024 ) # recieve da...
Posts
Showing posts from October, 2020