I'm able to start up the server script and get it running no problem, but every time i try to connect with my client script it keeps saying connection refused. I tried running the script on both Linux and windows. For the client and server I tried changing the HOST variable by using just "localhost" as well as gethostbyname.
import socket
from time import ctime
from random import *
PORT = 2222
s= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
HOST = socket.gethostbyname("localhost")
ADDRESS=(HOST,PORT)
def random_integer_division():
random.randint(1,500)
x = random.randint(1,500)
y = random.randint(1,500)
print(x)
print(y)
if x>y:
return(x//y)
else:
return(y//x)
s.bind(ADDRESS)
s.listen(7)
while True:
print("Waiting for connection. . .")
c, addr = s.accept()
#prints clients address
print(f'... conneceted form: {addr}')
c.send(bytes(f'Information returned form server: \n{str(random_integer_division())}'))
print("CLient disconnected")
c.close()
print("\nClient connection closed")
import socket
from codecs import decode
#HOST = "localhost"
PORT = 2222
HOST = socket.gethostbyname("localhost")
ADDRESS=(HOST,PORT)
#calling socket to create a bew sicket object
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(ADDRESS)
dayAndTime = decode(s.recv(BUFSIZE), "ascii")
print(dayAndTIme)
s.close()
print("\nConnection to server closed")