I am trying a simple client/server Python socket program between my MacBook Pro and Raspberry Pi 4. This code is from Computer Networking: A Top Down Approach [Kurose, Ross].



from socket import *

server_name = ''
server_port = 12345

client_socket = socket(AF_INET, SOCK_STREAM)
client_socket.connect((server_name, server_port))

message = input('string to capitalise: ')


modified_message = client_socket.recv(1024)

print('from server:', modified_message.decode())




from socket import *

server_port = 12345
server_socket = socket(AF_INET, SOCK_STREAM)         
server_socket.bind(('', server_port))               

print('the server is ready to receive')

while True :
    connection_socket, addr = server_socket.accept()     
    message = connection_socket.recv(1024).decode()
    modified_message = message.upper()

I have no issue when the the Pi is the server and Mac is the client, however vice versa (Pi = client, Mac = server) the client program will run but not display the prompt ('string to capialise:') or progress the program further.

I tried changing the socket type to UDP (SOCK_DGRAM) and this had no issues, so I am led to believe this might be a TCP matter. Has anyone else had this issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.