0

I am running a simple client/server model, and I've come with a minimum reproducible example of my code to show what my problems are.

Here is my server:

import pickle
import socket

PORT = 9001

server = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
server .bind(("", PORT))
server .listen()
print("Waiting for connection...")

while True:
    client_socket, address = server .accept()
    print(client_socket)
    print(f"connection from {address} as been established")
    message_dict = {
        'TYPE': 'MESSAGE',
        'VALUE': 'welcome to server'
    }
    client_socket.send(pickle.dumps(message_dict))
    client_socket.close() # close the client

Here is my TINY client:

import pickle
import socket
SERVER_IP = 'HERE IS MY IPV6 ADDRESS' # It's actually here, I just left it out for privacy
PORT = 9001

client = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
client.connect((SERVER_IP, PORT))
while True:
    message = pickle.loads(client.recv(10000))
    print(message)
    break

The SPECIFIC error I get on my laptop is a timeout error, as if it's not finding the server hosting.

Why is it I can't use this code on my laptop? For instance I want to run the server on my home PC, and run this client code on my laptop. I got it working once upon a time, but I seem to have forgotten how I did it, thanks for your help. It works on my local machine

  • You neglected to state what the problem is, but your client looks wrong. See [this answer](https://stackoverflow.com/a/43420503/238704) for why. – President James K. Polk Mar 04 '22 at 21:54
  • @PresidentJamesK.Polk my problem is that this code doesn't run on my laptop. And I don't think my client, is wrong, it runs on my PC. –  Mar 04 '22 at 22:38
  • 1) "Doesn't run" isn't a useful description of the problem. 2) It may run on your PC and still contain bugs which only manifest themselves in a different environment. 3) `message = pickle.loads(client.recv(10000))` is not always going to do what you think it should, so please read the linked answer in my first comment. – President James K. Polk Mar 04 '22 at 23:37
  • I read the above error. That pickle loads has never had any issues. The error I get is a timeout error, I'll add that into the original message for clarity. –  Mar 05 '22 at 00:02

0 Answers0