Code works on Ubuntu but not MAC

Hi All,

I am trying to write a client and server app.

Testing on 2 clients MAC 10.11.3 and Ubuntu 14.04.3 LTS.

When I run the client on the MAC in the PyCharm Community Edition 5.0.4 I do not get output on the server. The side seems to work fine but nothing is displayed on the server.

When I run the client from a shell prompt on Ubuntu I get output on the server.

Client program does not work on MAC, SFTP to Ubuntu and it works.

Server program running on Ubuntu 14.04.3 LTS.

 

Client.py

#!/usr/bin/python3

import socket

targetIP = "x.x.x.x" # actual IP Address in code - I do not get any socket errors
target_port = 9999

target = (targetIP, target_port)


def client():

clnt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
clnt.connect(target)
except socket.error as e:
print("Connect error ", e)
exit(1)

while True:

try:
msg = input("What do you want to send? ")
msg = bytes(msg, 'utf8')
clnt.send(msg, 2048)
except socket.errno as e:
print("Socket error ", e)

clnt.close()

client()

Server.py

#!/usr/bin/python3

import socket

hostIP = "0.0.0.0"
hostport = 9999

hosts = (hostIP, hostport)

def Server():

srvr = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srvr.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
srvr.bind(hosts)
srvr.listen(5)


clnt, addr = srvr.accept()

while True:
data = clnt.recv(2048)
if not data:
break
else:
print(data.decode("utf-8"))
srvr.close()

Server()

Please sign in to leave a comment.