Jan-09-2022, 04:06 PM
I'm new at Python with a Fortran, Basic and Visual Basic background, but I've managed to get a running program, but can't strip off the extra information.
This is the code:
Thanks!
This is the code:
import socket, sys host = '' port = 65432 socksize = 19 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) print("Server started on port: %s" % port) s.listen(1) print("Now listening...n") while True: conn, addr = s.accept() data = conn.recv(socksize) string = data.strip('/') #this line doesn't work if not data: #it gives me: TypeError: a bytes-like object is required, not 'str' x=1 else: print(data) print(string)It gets the data when I don't have the string & print(string) lines in there, but I was trying to strip off the b'GET / on the beginning of the data and the ' on the end. Being new to Python, does it always return the b'' when there is no data coming? Also once you write a program in Python, can it be compiled in Python so that it's statements are not visible? That's kind of why I put the dummy statement x=1 when there was no data in order to not have a running string of b'' when there is no data being received.
Thanks!