I have an assignment where I have to write TCP client server python programs to implement a basic voting application. There are only two candidates: JohnD and JaneD. I was testing the communication between the client and server. So when I run the client side, nothing happens. Could someone tell me why.
At first I was using "localhost" for serverName but I kept getting this error: clientSocket.connect(("localhost", serverPort)) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
So I set the serverName to my local IP. The client runs but nothing happens.
#TCP CLIENT#
from socket import*
#serverName = "localhost"
serverName = "131.100.39.41"
serverPort = 9001
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect(("131.100.39.41", serverPort))
option = input("Enter the voter name: ")
clientSocket.send(bytes(option, "utf-8"))
print("Name sent to server.", option)
clientSocket.close()
This is the server side.
#TCP SERVER#
from socket import*
serverPort = 9001
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(("", serverPort))
serverSocket.listen(1)
print("Server is up and running.")
while(1):
connectionSocket, addr = serverSocket.accept()
option = connectionSocket.recv(1024)
print("received from client", option)
serverSocket.close()