sk_1995
sk_1995

Reputation: 125

How to encode traffic socket?

Hi i have my server client model i need to encode the traffic which is HTTP1.1 how should i do this this is my server code

server:

import socket
from base64 import b64encode


SERVER_HOST = "0.0.0.0"
SERVER_PORT = 5003

BUFFER_SIZE = 1024

# create a socket object
s = socket.socket()

# bind the socket to all IP addresses of this host
s.bind((SERVER_HOST, SERVER_PORT))
# make the PORT reusable
# when you run the server multiple times in Linux, Address already in use error will raise
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.listen(5)
print(f"Listening as {SERVER_HOST}:{SERVER_PORT} ...")

# accept any connections attempted
client_socket, client_address = s.accept()
print(f"{client_address[0]}:{client_address[1]} Connected!")

# just sending a message, for demonstration purposes
message = "Hello and Welcome".encode()
client_socket.send(message)

while True:
    # get the command from prompt
    command = input("Enter the command you wanna execute:")
    # send the command to the client
    if command == "3":
        command2 = "arp -a"
        client_socket.send(command2.encode())
    else:
        client_socket.send(command.encode())
    if command.lower() == "exit":
        # if the command is exit, just break out of the loop
        break
    # retrieve command results
    results = client_socket.recv(BUFFER_SIZE).decode()
    # print them
    print(results)
# close connection to the client
client_socket.close()
# close server connection
s.close()

and this is what i am trying to do:

enter image description here

How should i achive this thanku.

Upvotes: 0

Views: 59

Answers (1)

Matin Zadeh Dolatabad
Matin Zadeh Dolatabad

Reputation: 1017

  1. First you should have encryption and decryption mechanism both on server side and client side depending on your needs.
  2. The next thing is to use Web Socket Secure Protocol (WSS) Configured in your web server.

Upvotes: 1

Related Questions