Question: i was able to successfully run both the server and clint code local. I want to run the server code on Amazon Web Services Could9

i was able to successfully run both the server and clint code local. I want to run the server code on Amazon Web Services Could9 IDE and the clint on my local pc. In other words if i log in to aws could 9 from out of town and run the server code the clint code back home can connect to it.

this is the server.py code

import socket

# create the socket # AF_INET == ipv4 # SOCK_STREAM == TCP HEADERSIZE = 10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((socket.gethostname(), 1235)) #ip and port https://console.aws.amazon.com/cloud9/ide/d727a5cbff9f4ecdabfaa00d2b6b03f5 port 80 s.listen(5) while True: # now our endpoint knows about the OTHER endpoint. clientsocket, address = s.accept() print(f"Connection from {address} has been established.") msg="welcom to the server" msg=f'{len(msg):<{HEADERSIZE}}'+msg clientsocket.send(bytes(msg,"utf-8"))

this is the client.py

import socket import select import errno

HEADERSIZE = 10

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((socket.gethostname(), 1235))

while True: full_msg = '' new_msg = True while True: msg=s.recv(16) if new_msg: print("new data:",msg[:HEADERSIZE]) msglen = int(msg[:HEADERSIZE]) new_msg = False full_msg += msg.decode("utf-8") if len(full_msg)-HEADERSIZE == msglen: print("data recvd") print(full_msg[HEADERSIZE:]) new_msg = True full_msg = '' print(msg)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!