server on python
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
server on python
import http.server
import socketserver
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
tcp client using sockets in python
from socket import *
import sys
import json
serverName = ""
serverPort = 6100
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
sample_data = {
"Aparna" : 1,
"Pooja" : 2,
"Shreya" : 3,
"Tanishq" : 4
}
serialized_data = json.dumps(sample_data) #data serialized
# clientSocket.send(str.encode(sample_data))
clientSocket.send(str.encode(serialized_data))
response_data = clientSocket.recv(1024)
print("Response data from server : ", response_data.decode())
clientSocket.close()
tcp server using sockets in python
import socket
from socket import *
import json
serverPort = 6100
serverSocket = socket(AF_INET, SOCK_STREAM)
# Avoiding : Python [Errno 98] Address already in use
serverSocket.bind(("", serverPort))
serverSocket.listen(1)
# TCP Server
print("The server is listening on PORT 6100")
while 1:
connectionSocket, addr = serverSocket.accept()
data = connectionSocket.recv(1024)
# De-serializing data
data_loaded = json.loads(data)
print("client Sent :n ", data_loaded)
# Sending response
connectionSocket.send(str.encode("Mil gya data"))
connectionSocket.close()
server in python
def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us