I'm wondering if anyone can give me reasons why Winsock is not connecting to WAN IP addresses.
It only connects to my LAN IP address or the looping address 127.0.0.1.
I'm running the client and the server on the same computer. I first run the server program, then verify that it is in fact listening on 0.0.0.0::3307 from the command prompt, then make the appropriate port forwarding by routing port 3307 to the computer in my LAN running the server. But it still cannot connect. I have also restarted my router.
What could be causing my client not to connect to the server running on the same computer?
I guess 0.0.0.0 as listening Adress is the Problem here.
May you inform yourself about IP address rooms and reserved addresses in detail.
Not quite shure, if i got you right here, but if you're able to get a connection using localhost's address or LAN IP Address everything's allright.
Related
I use socket connection to create client-server program. The server code have to wait for connection from client ip address.
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr("192.168.1.6"); //client ip address
Can I get connection from any ip address not specific ip address to 192.168.1.6 ?
The address you specify isn't the client's IP address, it's the address of the interface on your own host that it's going to listen on.
So, to listen only on localhost, you specify 127.0.0.1. To listen on the external interface that the outside world can see, you can specify that address.
Or, you can specify an address of 0.0.0.0, so a client can connect via any available interface.
Note that although it may initially seem a little crazy, it can actually make perfect sense to listen only on localhost. This lets you "cheat" a little bit on security. Instead of trying (and most likely failing) to do security on your own, an outside user forms an SSH tunnel to your computer, then has their client connect to your server through that tunnel. Your server only has to do its thing, and leaves all the authentication, privacy, etc., to SSH.
I have a computer, let's call it linux#home.
I have a dedicated distant linux server, let's call it linuxHost#datacenter.
I have a virtualbox virtual machine running windows 7 on the dedicated server, let's call it windowsGuest#datacenter.
I set up a NAT network interface on windowsGuest through virtualbox manager.
windowsGuest#datacenter is running a service that needs to access an sql database on linuxHost#datacenter, and that works fine. The same service on windowsHost needs to listen to connections on an udp port, let's say 12345. windowsGuest can access internet, web browsing works properly (doesn't need to, but that works fine).
So, now i need linux#home tu run a client application that connects on udp port 12345 on windowsGuest#datacenter. What i did is configure a port forward on the NAT network i use for windowsGuest :
-host ip : 127.0.0.1
-host port : 12346
-protocol : UDP
-guest ip : 10.0.2.4 (which is windowsGuest#datacenter ip address)
-guest port : 12345
I expect that any connection on linuxHost#datacenter on UDP port 12346 would be forwarded to windowsGuest#datacenter UDP port 12345, but that doesn't seem to happen.
a few more information :
- windowsGuest#datacenter's firewall is turned OFF
- linuxHost#datacenter runs iptables and is configured to allow any connection from linux#home, both tcp and udp.
- linuxHost#datacenter 's iptables doesn't log any blocked packets.
- I don't want to turn off iptables since linuxHost#datacenter is running other services and i don't want to expose that.
- I cannot test the client application on linuxHost#datacenter
What did I do wrong? Should i manually forward connections from internet to linuxHost#datacenter on port udp 12346 to 127.0.0.1:12345? should i configure the NAT port forwarding differently? Am i totally wrong and that's not the way i should manage this situation?
Thanks to this answer i could manage what i wanted. I had to modify my NAT port forward in the virtualbox manager preferences. The host ip field can be left blank, so that connections from any ip address would be forwarded to the guest.
What I want is to know how to bind two computers for my online game.
I made it using Server Socket and Client Socket and it works. But how can I do the same if it's unknown where this program is running. So I can't connect because I don't know who is the server. I was told that I can send broadcast message but now it's the third day of my endless attempts to do it...
I tried to write it like this (c++ builder 6):
ClientSocket->Socket->SendText("Message");
The address and host is 192.168.0.255;
And I run it twice in one computer at the same time but it does not work (because I don't know what to do then)).
Please, help me to find the server that I don't know beforehand.
I was told that I can send broadcast message
That is one way to do it, yes (it is not the only way). However, that only works if the client PC and server PC are connected to the same network.
The server app can open two listening sockets, one for TCP and one for UDP (IPv4 only) or Multicast (IPv4 or IPv6). IPv6 does not support UDP broadcasts, so you have to use Multicast instead.
The client app can then:
for UDP, send a message to the UDP port using the broadcast IPv4 address of the subnet that it is connected to. The message will be delivered to every device connected to that subnet. If the server PC is connected to the same subnet and the server app receives the broadcast message, it can send a reply back to the IPv4 address that sent the broadcast. When the client app receives the reply, it will know the IPv4 address that sent the reply.
for Multicast, subscribe to the server PC's Multicast group address. The server can periodically send its current IP address to the group, and any clients that are subscribed to the same group will receive it. When the client receives the message, it will know the IP address that sent the message.
Once the client has discovered the server's IP address, it can connect its TCP client socket to that IP address using the TCP port.
If the two PCs are not on the same network (ie, they are connecting over the Internet), then the above does not apply. The server will have to publish its current IP address somewhere that the client can find it, such as on a public website, or a Dynamic DNS service.
Of course, the simplest solution is to just ask the server admin for the server's current TCP IP/port, and then you can enter that into your client app's configuration as needed.
I tried to write it like this (c++ builder 6):
ClientSocket->Socket->SendText("Message");
TClientSocket uses TCP/IP. To send a subnet broadcast using UDP, you need to use UDP component instead. C++Builder 6 ships with FastNet, which has a TNMUDP component, as well as Indy, which has TIdUDPClient and TIdUDPServer components. Or, you can write your own UDP socket code using the WinSock API directly.
Indy also provides Multicast
The address and host is 192.168.0.255
That is the broadcast IP address for an IPv4 192.168.0.x subnet that has a 255.255.255.0 subnet mask. If that is your actual subnet configuration, and your client and server PCs are both connected to the 192.168.0.x subnet, then yes, you can send a UDP broadcast message to that IP address.
To obtain the subnet broadcast IP address, you can either:
calculate it manually. Use GetAdaptersInfo() or GetAdaptersAddresses() to get the local PC's current IPv4 address and subnet mask, then mask the bits of the IP address with the bits of the subnet mask using an AND operator, and then OR the result with the inverse bits of the network mask.
ask Windows. Create a socket and bind() it to the desired local network adapter. and then use WSAIoctl(SIO_GET_BROADCAST_ADDRESS) to query the broadcast IP address associated with that network.
I'm trying to access my WAMP server through my WAN IP.
My network infrastructure consists of a ISP's modem and a wireless router. Using win7.
I have setup the WAMP server on my laptop. I connected my laptop directly to my ISP's modem with a Ethernet cable and received the IP address 91.105.100.XXX. I was then able to connect to my WAMP server through this IP.
I disconnected my laptop form the modem and connected my modem to the wireless router. Then I connected with my laptop to the wireless network and tried to use the same IP address 91.105.100.XXX to access the WAMP server.
It was working for a while ~10 minutes. When joined to the wireless network I obtained another IP address - 46.109.65.XX. I tried to connect to the WAMP server using the new IP address 46.109.65.XX, but was unsuccessful. I am not able to reach the WAMP server when I’m connected to the wireless network through the WAN IP. Localhost works fine.
I have enabled port forwarding in my wireless routers configuration.
Tried to turn off firewall - no succes.
http://www.whatsmyip.org/port-scanner/server/ - show's that all ports are timed out.
Maybe I am doing something wrong or am I missing something?
Thanks for the help in advance.
UPDATE
I discovered that the main problem is with my 80 port, that doesn't want to work. When I use the port 8080 in configuration everything works fine. I even installed IIS and discovered the same problem. Both ports are forwarded in the routers configuration. I have a TL-WR740N router. After looking around for a while in settings I noticed that the routers web management port was set to 80, so I changed it. But the problem persists.
The modem is what talks to your ISP and therefore it is the modem that will be allocated a WAN IP address.
The router has a little DHCP server running in it and this will dynamically allocate IP addresses to your internal hardware as they power up their network cards. This could be your problem as when you were connected directly to the router your Laptops IP Address would have been 91.105.100.XXX but now it will be something like 192.168.X.Y.
So to run a server on the laptop you must configure it to NOT USE the DHCP allocated internal IP address or your port forwarding will only work if your laptop luckily gets the same internal ip address from the router each time you reboot the laptop.
So go to Control Panel -> Network and Sharing Center -> Change Adapter settings. This should get you to the Network Connections page of control panel.
Left click on the icon for your Wireless Network Connection and select Properties from the dropdown menu. On the properties dialog double click the Internet protocol version 4 (TCP/IPv4) line in the list to load the Properties dialog.
If you see a checkbox called Obtain an IP Address automatically and it is checked you are getting your ip address from the routers DHCP server.
Click the Use the following ip address checkbox and enter a valid ip address in the subnet range that your router is configured to allocate. It probably something like 192.168.0.x. Its a good idea here to check with the admin pages of your router, find what range the router is allocating and also there is normally a way of telling the DHCP server to allocate ip's from a range, for example it could be 192.168.0.100 to 192.168.0.200. This is the number range that dynamically allocated ips will come from, so you want to pick an ip for your laptop that is not between 100 and 200 so for example lets say 192.168.0.10. They do this expressly so you can setup servers with static ip address's. Some manufacturers leave high numbers for servers and some leave low numbers, so check your router.
It should look something like this, BUT CHECK YOUR OWN ROUTERS NUMBER RANGE!
Now your laptop is setup you now need to go and redo the port forwarding so that any communication on port 80 from the outside world is forwarded to port 80 on the static ip address you have just allocated to your laptop. Now comms should flow through the router to yout laptop.
I have a Host with VirtualBox installed and Guest installed (both with Windows XP SP3).
I do have connection between them. And also the guest have an internet connection.
I can connect via Remote Desktop Connection from Host to Guest, but I also want to be able to connect to Guest from any other PC. If can, how to achieve this?
Guest is using 2 network adapters, one NAT for sharing the internet connection and then one Host-only to be able for both machines to see each other on the local network.
Assuming you have an Internet router providing access to your ISP...
Change the VM networking from NAT to Bridged.
Check that the guest still has Internet connectivity after rebooting or ipconfig /renew.
Configure the router to give the guest a fixed IP address. (Typically, the guest can still use DHCP but the router is configured to give the guest the same IP address every time.)
Determine which ports and protocols needed to connect with the guest. E.G, TCP on port 3389 (RPD) for Remote Desktop.
Configure the router's "port-forwarding" feature to route external connections to the IP address of your guest. You can designate a different port for the external connections but that might not get through firewalls between the remote computer and its ISP.
Determine the external IP address of your Internet router.
Connect from the remote computer to the IP address and designated port.