0

I have this. But it only works locally. I always receive a connection timeout when I run the client. The port on the server is open to the default security group.

server.py:

import SocketServer

class MyTCPHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        self.data = self.request.recv(1024).strip()
        print self.client_address
        print self.data
        self.request.send(self.data.upper())

if __name__ == "__main__":
    HOST, PORT = "", 9800
    server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
    server.serve_forever()

client.py:

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto('Hello, world\n'('host.ip',  9800))
data = s.recv(1024)
s.close()
Glycerine
  • 7,157
  • 4
  • 39
  • 65

3 Answers3

1

On client you're using socket.SOCK_DGRAM which is UDP, yet you are using TCP server (which would be socket.SOCK_STREAM).

vartec
  • 131,205
  • 36
  • 218
  • 244
0

Looks like you're opening port 9800 but talking to port 9999

Simon Whitaker
  • 20,506
  • 4
  • 62
  • 79
0

The code works correctly.

Within the AWS console within the Networking and Security tab select Security Groups and within the default security profile under the 'inbound' tab - add your port to the list...

using a source of 0.0.0.0/0 will listen on all ports.

Glycerine
  • 7,157
  • 4
  • 39
  • 65