0

I have a server-client that work wonderfull when im trying to use them on my own machine. But - when im trying to use them on two different machines on the same Lan, it didnt work! Here is my connection:

Lan = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # Creates the socket object
Lan.connect(('localhost', port))

I dont understand why should it be a problem

xaxxon
  • 17,640
  • 4
  • 42
  • 70
dfsfg sfg
  • 67
  • 8

1 Answers1

1

When you are binding your socket, it gets bound to certain network interfaces, one of which is the loopback interface which is only available from your local computer. You're likely not binding to your actual network interface controller (NIC)

You want INADDR_ANY when you bind, though you didn't say what programming language, so I don't know specifically how to tell you to do it.

More info here:

understanding INADDR_ANY for socket programming - c

Community
  • 1
  • 1
xaxxon
  • 17,640
  • 4
  • 42
  • 70
  • Im using python so it should be an empty string. But what are the different beteween 'localhost' and empty string? – dfsfg sfg Oct 02 '16 at 07:32
  • localhost only listens on that port on the loopback device (a pretend network interface that is only useable from the same computer). An empty string listens on all network devices connected to your computer. If you had two physical network connections, you could specify for it to only listen on one of them. This is how a router works. – xaxxon Oct 02 '16 at 07:36
  • Thank man.. another last question - I did what you said and tried to use empty string. so i have this: __server_tunnel.connect(('', 1245))__ in the client, and this: __local_tunnel.bind(('', 12345))__ on the servr. and now, I cant even connect in the same computer! – dfsfg sfg Oct 02 '16 at 07:53
  • you have to tell the client where to connect to. It can use either your loopback device or your local network ip address, but it can't use "all of them". It can only use one. Localhost will work for a client on the same computer. So now that your server is listening on all devices, your client can connect on any one of them. Before you only had your server listening on localhost, so your clients could only connect on localhost -- so it worked on a local connection. – xaxxon Oct 02 '16 at 07:57
  • But also if im trying to use the client in another computer with empty string, its not work.. And in that situation its have just the router, so it cant be confused.. – dfsfg sfg Oct 02 '16 at 08:06
  • on another computer your client has to have the actual IP address of your computer with the server. If both computers are on the same LAN, then you can use your LAN ip address like 10.x.y.z or 192.168.x.y. If its' not on the same LAN, you may have to set up port forwarding on your router. – xaxxon Oct 02 '16 at 08:07
  • I could do that, but its restricts me from using the software on 2 other computers of my friends (which I not know there IP, and I dont want to go every time a man download my software and change tell him to change the IP before he working with it. I want the to computers to know hoe to connect the Lan router automatically without any help of me.) – dfsfg sfg Oct 02 '16 at 08:14
  • Then you need to have dns resolution in place – xaxxon Oct 02 '16 at 21:08