Question
the code for my server is getting a strange error: python3 echoServ.py 10000 Traceback (most recent call last): File /home/susaf/Desktop/echoServ.py, line 42, in csocks, addr
the code for my server is getting a strange error:
python3 echoServ.py 10000 Traceback (most recent call last): File "/home/susaf/Desktop/echoServ.py", line 42, in
is there something wrong with my code?
import socket import struct import sys import statistics
def send_data(sock, data): msg = struct.pack('!iii', data[0], data[1], int(data[2]*100)) sock.sendall(msg)
def recv_data(sock): msg = sock.recv() data = struct.unpack('!i', msg) return (data[0], data[1], data[2] / 100)
#multiple servers list csocks = [] sSocket = []
#number of command line arguments if(len(sys.argv) != 2): print("Usage: python3 Program 01 Server
#port from user input port = int(sys.argv[1])
#TCP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#bind socket to port sock.bind(('localhost', port))
#listen for incoming connections sock.listen(5) sock.setblocking(False) sSocket.append(sock)
while True: csocks, addr = sock.accept() print("Connected by", addr) min_value = None max_value = None count = 0 total = 0 while True: data = recv_data(csocks) if data[0] == -1: break print("Received value")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started