Sync TCP Client in multi-client application without lags - delphi

I have application, whitch connents to N devices trought the network.
The problem is:
TCP Client class isn't async, I'm send the command to device, I want get answer now.
So, 2 or more active clients makes my app frozen.
Any ideas how to do some, that's will not freeze my application if many devices is enabled at one time?
TCP Client class uses Synapse classes package.
Thanks!

To avoid application hang, use a separate thread for every TCP client connection.
The thread then will run independently, connect to the device, and do the communication.
Note that the thread must not access objects/data in the main application thread without proper synchronization.

Related

To close NSStream objects before resigning active

I have an NSInputStream and NSOutputStream scheduled in a non-main-thread run loop. I'm using CFStreamCreatePairWithSocketToHost. The remote endpoint is an external device that communicates with the app with TCP over wifi.
When applicationWillResignActive is called, I want to close these. I want to be guaranteed that they will close, because another app may want to communicate with the same device, and the device only accepts one TCP connection.
Additional information:
It is a frequent occurrence in the context of this device that multiple apps may need to communicate with the device.
I have tried using performSelector:onThread:withObject:waitUntilDone:
(with waitUntilDone:YES) in applicationWillResignActive. Sometimes this doesn't work, and in those cases it seems that the selector does not get called.
My understanding is that I can't close the NSStream objects or destroy the task queue from the main thread.
I can not change how the device receives connections. It listens on one address/port for TCP connections, and allows only one connection (it doesn't multiplex connections by source port).
Use dispatch_sync() to the background queue.

Sometimes socket dies when switching wifi to 3g iOS posix sockets

I've searched the web extensively but haven't found a good answer to this.
Im writing a socket based application in C++ using posix sockets on iOS/Android.
When switching from wifi->3g, SOMETIMES the socket goes dead without giving any errors when reading/writing.
I can use the reachability API on iOS (and similar on android) to detect when the network switches.
I am destroying/recreating the socket when this occurs. The problem is if the socket is alive, the server will receive the signal when I close the socket. If the server receives the close signal, it will assume the client disconnected intentionally and notify others about this, which is not what I want. If the socket is dead, the server doesn't receive this signal and everything is OK.
How do other people handle this scenario? I really don't want to use a timeout to detect this.
Why does it only sometimes die too? And how can I tell the socket is actually dead?
Just to close this issue, this is the approach I'm taking.
When switching networks, I'm sending a ping-and-reconnect packet to the server, AND creating a new socket.
Which ever responds first, I close the other connection.
Required a bit of server side changes to handle this correctly too

How to be sure to receive requests over the network? (for the staff in a shop for example)

If I want to make sure that a device receives a message, over the network, for an app used by sellers in a shop for example.
I heard push notifications are not 100% reliable, sometimes some of the notifications don't arrive, or not on time.
The app could be in a shop, where the staff communicate with one another, and there could be 10 devices connected. (ipad, iphones)
edit 1: I heard about sockets, is it the right direction to go?
EDIT 2:
I am not sure why a socket should be used, rather than a webserver for example, I found these 2 sentences (source raywenderlich) :
You can send connected clients data whenever you want, rather than requiring the clients to poll.
You can write socket servers without a dependency of a web server, and can write in the language of your choice : don't understand what the "dependency" is?
Does it also mean :
Sockets let 2 (or more) specific devices to connect one another in a private connection, compared to webservers where everybody could connect if there is no login/password?
EDIT 3 : Maybe a bluetooth solution with MultiPeerConnectivity would be better...
Sockets, and push notifications in general, are only as reliable as the network the user is connected to. If your looking to circumvent network reliability where a 100% success rate is guaranteed, in a Shop environment where users are in close proximity, you can look into GKSession as part of the GameKit.framework
Or you could look into Bonjour or client/service discovery protocols that makes the process of "knowing" peers in a network
I see you tagged Parse.com, again, the reliability of Push Notifications is highly dependent on the reachability, however, most issues that arise with Parse is dev-end related, not product related.
EDIT I forgot to mention MultiPeerConnectivity
If you use TCP sockets, you are guaranteed the message will be delivered, and very quickly too.
However, the application would have to be open (and most likely in the foreground) to receive the messages. You can always have the server wait till the client connects to send the message.
I would suggest using a combination of both TCP sockets and push notifications (for when the app is closed).

Is using a socket connection possible within iOS 7 background fetch mode?

Apple added in iOS 7 new possibility to execute activities in the background, fetch mode, which can be used e.g. for Twitter, when frequently small amounts of data need to be downloaded (official description: The app regularly downloads and processes small amounts of content from the network.),Apple Document Reference
However, I need to use a TCP connection.
Does anyone know whenever TCP connection may be used in such scenario between the calls?
The scenario is:
I open the TCP socket in the beginning and then the application can use it in these fetch calls. Of course handlers are needed when the TCP connection drops, but there is a difference between rare necessity to reconnect and constant (i.e. in each fetch iteration) need to reconnect.

socket connection in iOS and background tasks

I am designing an app that needs to exchange data in real time over network and I am planning to use socket connection to achieve this. To keep the socket connection open in background I plan to declare my app as a VOIP app (I already know apple's rule prohibiting this and willing to take the risk), and use keepAliveTimeout to keep connections alive.
Now can I declare and own a socket which will listen to any incoming data or I have to use an existing/specific socket given by Apple? Also is the port unique per app or per phone? Means if my app is continuing in background and also a call comes over Skype would they interfere with each other?
Thanks in advance for response. Help would be appreciated.

Resources