3

In regular request/response between client and server, first a client initiates a request to server, then server responses. Assume that the server always knows the IP address of its clients (note that clients have dynamic IP address). Is it possible for server to initiate the request first? By "initiate the request first" I mean server must be able to send data to clients whenever wants. Thanks

3
  • 2
    In the IP protocol, there are no clients and servers, only senders and receivers. If a system knows the IP address of another system, it can send an IP packet to that system. Are you talking about TCP? Could you provide more details so it is clear what you are asking or what problem you are trying to solve?
    – Gerben
    Oct 15, 2015 at 9:29
  • Hmm.. Yes you're right. Assume that you wanna transfer data (reliable) between two devices on the Internet. So the chances are TCP must be used. I have a device that has static IP address and many distributed(all connected to Internet, not in the same LAN) devices that don't have static IP address. All the distributed devices have the IP address of the central device so they can initiate a request to central device. I want the central device to send data to distributed devices whenever it wants. Thanks
    – Mahmoud
    Oct 15, 2015 at 13:09
  • 1
    We really need more information to answer definitively. At the moment, any answer we provide will be assuming a lot of information. Can you describe how your application works? Can you describe whether your "clients" are sitting on Private Networks or whether they have static addresses? Can you describe what port/protocol your application runs over? Those will help us give you a definitive answer.
    – Eddie
    Nov 14, 2015 at 16:01

3 Answers 3

1

Assume that you wanna transfer data (reliable) between two devices on the Internet. So the chances are TCP must be used. I have a device that has static IP address and many distributed(all connected to Internet, not in the same LAN) devices that don't have static IP address. All the distributed devices have the IP address of the central device so they can initiate a request to central device. I want the central device to send data to distributed devices whenever it wants. Thanks

To establish a TCP connection one end (the "server") listens and the other end (the "client") connects to it.

Once the TCP connection is established either end can send data to the other end whenever it wants.

In practice however your clients are likely to be behind firewalls or nats and that adds some complications.

  1. It is unlikely that your server will be able to initiate a connection to a listner on the client. There are tricks that can sometimes be used but they don't always work.

  2. If a TCP connection sits idle for too long then firewalls/NATs are likely to cut it off.

  3. Certain network glitches can cause a connection to be cut off without the endpoints realising it is cut off.

The result is that if you are deploying clients on arbitary networks and you need the server (which we assume has an IP on the public internet) to be able to send messsages to them the clients need to establish a permanent TCP connection to the server and they need to periodically send a test/keepalive message to the server. IF they get no reply to their test/keepalive message then they need to tear down the TCP connection and try establishing a new one.

0

As Gerben mentioned in comment, in IP protocol there is no server or client. If you know IP and port of the client, then you can send data.

However, the client has to listen on some port, because otherwise the system doesn't know to which application are the data meant and it will just discard them.

So the answer to your question whether it is possible for server to initiate data transmission is yes and no. Yes it is possible, but your client has to listen on some port first, so you need the client running before you send data.

Edit: this is assuming your clients have public IPs or are on the same network as server. If they use NAT, then it would be more complicated.

5
  • 2
    Actually, there are also no ports in IP...
    – Gerben
    Oct 15, 2015 at 10:49
  • That's true. I just assumed Mahmoud is talking about application on higher layer than 4, most likely application layer.
    – Fuki
    Oct 15, 2015 at 11:46
  • Of course the client has to listen on the same port. My clients don't have static IP address and they are distribute all over the city (connected to the Internet). I saw some say about "Persistent Connection" :-?
    – Mahmoud
    Oct 15, 2015 at 13:13
  • By the way I design the clients and server. I mean I can change the codes that are running on the nodes.
    – Mahmoud
    Oct 15, 2015 at 13:18
  • 1
    Well as long as you have the IP and know which port to use, then it should work, but I know nothing about "Persistent Connection", it seems like some programming stuff, so you may want to try different forum for that.
    – Fuki
    Oct 15, 2015 at 16:18
0

Assuming you are talking about TCP/UDP, if you know both connection endpoints (IP and Port), you can do whatever you want with the nodes. Remember though, that to connect to a host, it has to be expecting a connection (the other host has to be listening in a specific port, so it would kinda act like a server too).

About what you said of persistent connections (keep-alive) it's an HTTP method to receive multiple HTTP requests and responses, so it's not what you are looking for. Anyways, this is a layer 4 protocol and I think it shouldn't be discussed here.

Not the answer you're looking for? Browse other questions tagged or ask your own question.