-1

I have to make connections form one server to many PCs ( ~1000 PC). These PC are connected by a Wifi Network in the same Building.

Each PC have a dedicated connection with the server. Form its IP address, the server knows the specific data to generate to him.

I have to send a dedicated short strings over network to each PC. (~30 characters by a string)

The dedicated string is sent by a frequency of 30 strings by a second to each PC.

The problem is that these sent data are critical and should be sent in real time.

Which solution is the faster and the most robust in my case?

ProEns08
  • 1,856
  • 2
  • 22
  • 38

4 Answers4

4

I assume you have two PC connected by some Ethernet or wifi, or good enough modern Internet connection (both on Earth; no interplanetary ...; no pigeon IP RFC1149 or 1200 baud analog modem from the 1970s). Then 30 strings of about 30 chars per second is about a kilobyte per second, not a big deal, and certainly not high frequency as you claim. My current fiber internet connection at home (near Paris, France) is able of a dozen of megabytes per second of download, and at least a megabyte per second of upload. A few years ago it was ADSL with about one megabyte per second download. I never had at home an Internet connection for which a kilobyte each second was a high load. (If you are in interplanetary space, or in the most remote and desolate places of Africa or Antarctica, then 1Kbyte/sec might be an issue in 2016, but then you are very unlucky regarding Internet connection).

Your HTTP setup might use websockets (so a bit like your second solution). You could use libonion (an HTTP server library) on the server side, and libcurl (an HTTP client library) on the client side. Periodically polling (e.g. issuing an HTTP request twenty times per second) would require more resources (but that is still manageable). An HTTP connection would be slower, because HTTP adds some overhead (the headers in HTTP requests & responses).

Notice that HTTP protocol is above TCP/IP, so will definitely use BSD sockets on operating systems providing them (Linux, Windows, MacOSX, ...). So a "web solution" is using sockets already.

If you use sockets, you'll need to define a protocol on them (or using some existing one, like HTTP or JSONRPC).

I'll go for a socket approach. Probably some JSON related thing like JSONRPC. Be aware, if you code on the socket API, that TCP/IP is a stream protocol without message boundaries. You'll need to buffer on both sides, and define some message boundary conventions. You might send JSON, terminated by a newline (the ending newline is JSON compatible, and facilitate delimiting messages).

You might be interested by messaging libraries such as 0mq.

addenda (after question edition)

Your new question is widely different (thousands of PCs, not only two of them; I guess they are in the same building, or at least the same continent.). You need about 1000 * 30 * 30 i.e. less than a megabyte per second of bandwidth. I would still suggest using some sockets. Probably 0mq is even more relevant. You might make each message some JSON. You need to document very well the protocol you are using. Probably, you want the server to have several threads (e.g. a dozen, not many thousands of threads) to loop on emitting messages (on TCP). Perhaps you might want to have a server with several Ethernet connections (but a megabyte per second can go on one single Ethernet, even a slow 100Mbits/sec one).

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Your latest edits made me puzzled a bit. JSON is a message on it's own, so why you do not need artifical message boundaries? – SergeyA Apr 28 '16 at 13:49
  • Because by painful experience, hand-coding a JSON thing without an explicit end of message border is slightly painful. Adding a newline at the end is JSON compatible and simplifies things a big lot. – Basile Starynkevitch Apr 28 '16 at 13:51
  • Not sure how exactly it is painful, JSON parsing needs stream, and implementing stream interface on top of TCP socket is trivial. – SergeyA Apr 28 '16 at 13:56
  • @BasileStarynkevitch: Sorry, I should delete the question if it is still not welcomed by the community (3 downvotes) in less than one hour. I should respect the community. This is one result of SergeA downvote propaganda. – ProEns08 Apr 28 '16 at 14:01
  • Not only. Your question is badly asked, and you did not improve it after I asked for improving editions. So I also downvoted it (and I will revert my downvote if you edit your question properly by giving *much more context*). – Basile Starynkevitch Apr 28 '16 at 14:08
  • @BasileStarynkevitch: Yes thank you. But I am still downvoted. – ProEns08 Apr 28 '16 at 14:55
  • @ProEns08: That is not a big deal to be downvoted. Next time you ask some question here, give a lot more details and motivations. IMHO giving too much details in a question is much better than not giving enough. And every question should be motivated, by giving some concrete context. – Basile Starynkevitch Apr 28 '16 at 15:25
  • @BasileStarynkevitch: yes, thank you, +1. which is the best 0mq or rabbitmq? – ProEns08 May 02 '16 at 11:03
  • @SergeyA do you suggest to execute stream parsing on every incoming data chunk until the JSON is full? Message boundaries are nice for preformance. – Fr0sT Jan 23 '17 at 11:08
2

30 bytes, 30 times per second, is 900 bytes per second. That's not fast at all; either method will work fine. And note that an HTTP connection uses a socket anyway.

It sounds like your "socket" option implies keeping a socket connection open all the time, as opposed to HTTP, where (typically) a separate connection is opened for each request. I think what you're really asking is:

  • Make the client periodically ask the server if there's new data, or
  • Have the server immediately send the new data as soon as it's available.

That depends entirely on what your program's requirements are, which we don't know.

Wyzard
  • 33,849
  • 3
  • 67
  • 87
1

A thousand biderectional TCP communications require 1000 sockets (unless you want to open and close connection for every string sent, but that would be a major performance drain).

That is dangerously close to the customary soft limit of maximum open file descriptors (which is 1024). And it is 25% of customary hard limit of 4096. Given that, I find that TCP is not well suited here.

Instead, I suggest going with UDP. With UDP, you'd need only handful of sockets (even one would do, but with multiple you could scale better). It would have a problem of reliability, but you can implement some sort of it on top of UDP.

SergeyA
  • 61,605
  • 5
  • 78
  • 137
0

Please make yourself familiar with the OSI model. Sockets (UDP, TCP) are on layer 4, HTTP is on layer 5, thus using a layer 4 protocol already.

weismat
  • 7,195
  • 3
  • 43
  • 58
  • 1
    OSI model is good as academics only. In real life, the boundaries are blurred. – SergeyA Apr 28 '16 at 13:42
  • 1
    For someone new, it is a good starting point to get an idea of the structure. – weismat Apr 28 '16 at 13:43
  • This is true - and this is why I mentioned 'academics'. – SergeyA Apr 28 '16 at 13:44
  • @Sergey: Are you OK now with 4 downvotes. – ProEns08 Apr 28 '16 at 13:48
  • @ProEns08, those downvotes should hint you to remove your question :) Remember, once the question is delted, it's downvotes no longer count against your carma! – SergeyA Apr 28 '16 at 13:49
  • @SergeyA They might not count towards rep but they do count towards question rate limits and bans. – NathanOliver Apr 28 '16 at 13:51
  • @NathanOliver, didn't know that. Seems a good thing to me! :) – SergeyA Apr 28 '16 at 13:54
  • @SergeyA: You make against me the greatest propaganda for dwnovoting my question and you don't know the effect. You should know that one of the result of your downvote compaign is to ban me from ask again. – ProEns08 Apr 28 '16 at 13:57
  • 1
    @ProEns08, your question is still bad, and bad question deserves downvote. Sorry, fact of life. Be more careful next time, do your research before asking and your question will be upvoted. – SergeyA Apr 28 '16 at 13:59
  • @weismat:Sorry, I should delete the question if it is still not welcomed by the community (3 downvotes) in less than one hour. I should respect the community. This is one result of SergeA downvote propaganda. – ProEns08 Apr 28 '16 at 14:03
  • 1
    No problem at all.... – weismat Apr 28 '16 at 14:04
  • 2
    @ProEns08, there are 5 downvotes. And you really give me too much credit. I am not that charismatic. – SergeyA Apr 28 '16 at 14:04
  • 1
    @SergeyA: You could edit the question to improve it. Why not to be constructive? – ProEns08 Apr 28 '16 at 14:08
  • @SergeyA: I am against your 6 downvotes and not happy here: http://stackoverflow.com/questions/36263531/how-can-semaphores-implemented-on-multi-core-systems. If I know how to improve it, I would protect it from downvotes. – ProEns08 Apr 28 '16 at 14:12
  • @ProEns08: you are the best person (the OP, not SergeyA!) to edit and *improve* your own question. You know details that we can only blindly guess (e.g. I guessed that no PC is in Antarctica, but you are the only one to know that for sure) – Basile Starynkevitch Apr 28 '16 at 14:13
  • 1
    @ProEns08, how is that relevant? People thought my semaphores question bad. I actually believe they didn't understand it fully and downvoted incorrectly. I can live with those downvotes. – SergeyA Apr 28 '16 at 14:14
  • @BasileStarynkevitch: Yes thank you. I would improve it. – ProEns08 Apr 28 '16 at 14:15
  • Hurry up. Your question is likely to be soon closed, then it would be too late for improving editions. – Basile Starynkevitch Apr 28 '16 at 14:16
  • @SergeyA: I want to say that we should be constuctive and help each others. Why to be agressive and attack the upvoters. – ProEns08 Apr 28 '16 at 14:17
  • 1
    @BasileStarynkevitch: _"then it would be too late for improving editions"_ That's not true. The question will be "on hold" for seven days, which is _literally_ designed to allow the OP time to edit/salvage their question before the banner later says "closed". And, even then, it can be re-opened and there's a whole review queue dedicated to revealing edited closed questions and asking reviewers whether it's time to re-open them. – Lightness Races in Orbit Apr 28 '16 at 14:24
  • @ProEns08: SergeyA was not agressive... Perhaps he has used the "insulting" word in some deleted comment, but that adjective (an Americanism) was for the connection between the PCs not for you as a person. – Basile Starynkevitch Apr 28 '16 at 14:24
  • @BasileStarynkevitch, yes I did and regret this. And yes, it was not about OP - and in one of those deleted comments I stated this very clear, that is is not directed towards OP. However, the comment is gone now :) – SergeyA Apr 28 '16 at 14:28