I am trying a server to get data "www.example.com" with the port "xxxx" and my ip is "192.168.10.6". The server has to send the response to my app through port "yyyy". I sent a request to the server, but the sever sends the response to the ip "203.146.0.9" port "yyyy". And the server shows the log as "Connection rejected by 203.146.0.9:yyyy(port)".
I am very much beginner to the network programming. According to my knowledge the server sends the response to my DNS/router. Which not accepts the communication on that port.
My iPhone app listens the port of the device and not the dns port. How to make my app to listen the DNS port or else how to make the DNS to forward the response comes from the particular server to my local iP.
I gone through some post and some specified the "Bonjour". But I have no idea about that. Can anyone please help me by pointing out such example or documentation to clear this issue?
Short answer: you can't
Long answer:
Whenever you connect to a server through your iPhone, the phone forwards the request to the carrier's router via 3G or GPRS or some other protocol, which forwards the connection to the destination server. On the receiving end, the server sees the router's IP address, not the phone's. Actually, the phone's IP address only exists on the carrier's router, and nowhere else on the internet. You cannot create a public server from an iPhone (only maybe on a local WiFi connection, or if the carrier assigns the phone a public routable IP address). Therefore, you cannot initiate a connection from your server to some iPhone. If you want two way communication, you can however use the iPhone to connect to the server and on the server side, use that channel to send data to the iPhone. NAT may be another solution, but once again, it requires special provisions from your carrier, which may be an option for you, but usually not your clients having iPhones.
Related
I want to have 2 applications that communicate over internet, socket base. Each is a server and a client. Each applications will only know the IP address of the other peer, but not the port number. Port number is random, whatever is free on the system when the application starts.
Idea would be one application sends some kind of discovery message containing its own port number as payload data. The other receives the message and starts communication using the received port number.
Could someone recommend how to send this "discovery message" to detect the port number used by the other peer, without using a server to exchange the information?
Thanks
I had made a small web server program that can handle HTTP requests, it worked fine on loopback ip address. I Had connected the host computer to a wifi using a router, i can access that program using another device connected to the same router using a web browser. but the problem is when i tried to open the open the command from the device connected to another router/internet, it didnt connect.
I had used the address like "10.0.0.4:8080" to connect with the device on the same router. later i tried with the public IP address to connect to my web server program but it didnt work!
what am i missing in giving the correct ip address and port number such that it could be connected with the devices that arent connected with my router.
You have to add port forwarding on the router from outside to the specific IP of the device. Then use public IP from outside and public or private from LAN. Probably also set it to static internal IP from device or router.
DMZ to the device is also an option but is overkill.
That way lot of bots will scan your server so carefull with the security and what you expose.
Let's assume I'm in computer A, I have a few servers running on different ports, but all are basically an instance of the same program (just binding to different ports). Now, computer B, a client, does he need to know what port is the software he wishes to connect to on computer A?
The point is, I am implementing some sort of communication similar to sockets. Everything should work fine but I'm not sure how to create the initial-message from a computer to another - I just don't know to what port to send it to. Does the client know the port he's sending to on the server?
Say here (client): clientsocket.connect(('localhost', 8089)), does the client connect a server running on port 8089? If so, what port is his socket on (what port is he using for the client?
Yes. The only way for the network stack on computer A to know which process to deliver an incoming packet is for computer B to set the correct port in the packet. A web server runs on port 80 by default, but a machine running several distinct web servers will run them on distinct ports, and a client must be specific about which server they want to connect to. http://example.com, http://example.com:8080, and http://example.com:12345 would refer to the servers running on example.com on ports 80, 8080, and 12345, respectively.
In order to know which port to use in your client, you need to read the documentation for the server you want to connect to.
Going in the other direction, the port used by the client to receive responses is typically set by the networking stack automatically. The client doesn't need to do anything special to set it, and the server simply sends packets back to the address/port found in the source portion of the incoming packet.
I have a client-server based project implemented with boost::asio. It works fine if client and server are running in the same network, let say server ip=192.168.2.20 and client ip=192.168.2.100. But if I change the ip address of the server to 192.168.3.20 the connection is not astablished, I get socket timeout. At the same time I'm able to ping 192.168.2.20 from the server's host( I mean from 192.168.3.x network ) and I'm able to do it vica versa.
What could be a problem here?
I have a question about network connections among computers.
I've made some applications where messages pass through the Internet (via sockets) to make a connection between two devices. However, a strong condition is that two devices must be connected to the same network.
Can anyone give me a trick how to create a communication using sockets between two computers even if they are connected to different netwkorks?
Thank you in advance.
Here is a great tutorial on how to use sockets and general networking
(in java) http://www.thenewboston.org/watch.php?cat=25&number=38
In order to communicate between two diffrent networks over the internet, you will need to do something called port forwarding. What that does is that when your public IP of your network receives a packet with a spesific port number. The router knows where to send that packet to which local IP.
If you dont port forward and receive some data. The router doesent know where to send the packet. Therefore it discards it, which means others wont be able to connect to you.
You will only need to port forward the network with your server (using the example i linked). How you do that is by logging in to your router, and say that a port which the server uses gets forwarded to the IP of the PC hosting the server.
On the other network (client) you will need to change the IP address of which the client shall connect to. That IP address needs to be your public IP of your server's network. You can find that by connecting to the server's network and go to: http://www.whatsmyip.org/ . Keep in mind that public IP addresses may change over time.
Hope this helped!
-Kad