-1

I was having my first few tries with sockets but I kind of stuck here: I really don't understand why sockets will work only with private ip's here's the code:

    import socket
    s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind(("12.34.56.78",3307))
    s.listen(5)

could you explain me where is the problem?

CodEdo
  • 91
  • 2
  • 9

1 Answers1

0

First of all (as Mark noted in comment): the IP address should be a string, i.e.:

s.bind(("12.34.56.78",3307))

Also, if that is the IP address you are actually trying to bind to, it won't work. You can only bind to a local IP address of a network adapter.

arghol
  • 745
  • 9
  • 21
  • Thanks a lot, in case I would like to connect to the socket from outside my network what would I need to do? – CodEdo Dec 22 '19 at 09:33
  • You need to connect to your public IP address using the port 3307. You can find your public IP address by using a service such as [whatismyip](https://www.whatismyip.com/). If you are behind a router with NAT you probably need to configure port forwarding for the port 3307 too, otherwise the router doesn't know where to forward the traffic. – arghol Dec 22 '19 at 10:01