Python Forum

Full Version: typeerror:byte like object is required
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
#server.py
import socket # Import socket module
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.bind((host, port)) # Bind to the port
s.listen(5) # Now wait for client connection.
while True:
print("waiting for client connection" )
c, addr = s.accept() # Establish connection with client.
print ('Got connection from', addr)
c.send('Thank you for connecting'))
c.close() # Close the connection
#client.py
import socket # Import socket module
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
print(s.recv(1024))
s.close # Close the socket when done
Quote:
s.close # Close the socket when done

Your comment doesn't match your code. If you want to close the socket, you need to call the close() function. Just referencing the function doesn't call it.