What is the difference between ServerSockets and Websockets? - dart

There appears to be 2 ways to maintain an open connection between a Dart server and a Dart client: ServerSocket and Websocket.
https://www.dartlang.org/dart-by-example/#sockets
https://www.dartlang.org/dart-by-example/#websockets
When is it best to use one instead of the other?

Websocket is a protocol build on top normal sockets that are based on the TCP protocol (ServerSocket and Socket). Websockets give you more comfort during programing, because it helps you with:
Framing: TCP is stream based, Websockets allow you to send packages. You don't have to find the start and end of your package on your own.
Closing Handshake: You can send a connection close reason.
Security (in browser context, not required in console application context)
You can also access your Websocket server via a Webbrowser API.
If you want to work together with existing Servers / Clients that are using TCP, that you have to use ServerSockets. Websockets and ServerSockets are not compatible (intentionally, for security reasons).
As Websockets have more internal stuff to do the performance and throughput will not be as good as raw TCP, but this point is negligible.
Both protocols can be used with encryption, Websockets by using a HTTPS connection (wss://) and TCP using TLS (SecureSocket and SecureServerSocket).
For more details about Websockets, take a look at the RFC. RawDatagramSocket allows you to use the UDP protocol in addition to the TCP based ServerSockets.

Related

Compare mqtt over websocket and direct mqtt on ESP8266

Can someone explain to me the advantages and disadvantages when transmitting MQTT over Websocket instead of direct transmission over MQTT? . I am planning to use MQTT over websocket for my project on ESP8266. I am in a situation where I cannot use MQTT directly
The major upside to MQTT over Websockets for none browser based clients is that it allows you to make use of HTTP proxies (assuming the client also supports proxies) when you don't have a direct connection to the broker.
The other advantage is that if you have a mix of devices and web based MQTT clients that you only need to expose one port to service both sets of clients.
You do pay a price for a larger connect/setup payload with MQTT over Websockets because you have the HTTP Upgrade message that needs to be handled before the normal MQTT connection starts.

GPRS -Reliable, Fast, Guarantee Communication

I have recently developed a GPRS communication software using Arduino (embedded application) and GSM modem to communicate to/fro from web server. However I found that there is enough delay and request getting dropped (response timeout) while receiving a response from server at client side.
The techniques I have tried are - TCP / UDP / HTTPS / HTTP.
In my case our requirement is for a Reliable, Fast, Guarantee Communication between client and server.
Please let me know which communication stack would establish the same or rather be best to be used?
Thanks in advance
GPRS gives you direct IP access to the Internet. If you're losing packets or suffering large delays when sending packets to your server then this sounds like a problem with the mobile ISP.
As Ken mentioned GPRS will provide you IP connectivity to the internet (or some private network if applicable).
On top of IP you can choose to use a number of higher layer protocols, the two most common of which are probably UDP and TCP.
UDP is 'connectionless' and provides very little in the way of error detection/correction etc.
TCP is connection orientated (which means that some signalling happens back and forth to establish a virtual 'connection' first). It also includes mechanisms to provide error detection, error correction and correct packet delivery order. TCP also includes flow control, to avoid the sender overloading the receiver, and congestion control to avoid network overload.
There is a perception that UDP is faster than TCP, but I think it depends on the situation - take a look at this discussion for some further discussion on speed, reliability etc between UDP and TCP (go down through all the high scored answers):
UDP vs TCP, how much faster is it?
For your requirements, I would think a solution based on TCP/IP is probably what you want.
Whether you want to use HTTP or some other protocol on top of that is going to be dependent on your solution, and to some extent on personal preference.

Is there a public UDP site to test ObjC code?

I'm attempting to learn UDP coding as a neophyte.
I've been doing iOS development for years and want to start learning to do some basic network coding using the UDP protocol.
Is there a practice site to play with where I can't do any harm?
Or... is it possible to merely wire up the Apache server that comes with OS X and work with that?
This is intended to be for an iOS environment so would at least have to work via simulation.
Apache is an HTTP server, HTTP being a protocol built on TCP not UDP. You're probably going to be best off trying to write both a client and server that run in the same application and having them talk to each other via UDP.
FWIW, DNS is based on UDP, so talking to a public DNS server might be a good starting point.

Server separate connection per client

The simple way to support multiple clients is to fork a process for each incoming connection and handle the client through that process and the other process then listens on the default port.
However I have heard that not only is the process forked, but the connection itself is redirected from the default port at which the server is listening to a different port on the server side. This improves performance. I am unable to find any reliable reference to this topic. Is this a standard procedure
This is not the case for most protocols on the internet. For example, public web servers will always listen on port 80 for every request. FTP servers on port 21 and so on. Where did you get your information? With more information on the context, someone might be able to help establish the circumstances you're talking about. What's your source?

Delphi transparent proxy for a TCP connection

Anyone know of any examples of a TCP sockets proxy application written in Delphi? I am building a small broker application that needs to listen for socket connections on a given TCP port, read a XML data packet sent over the connection, serve the request via TCP to a server chosen from a pool of available back end servers, and deliver the resulting response back to the originating TCP connection.
I am very familiar with TCP and socket-level programming, but would prefer to find sample code as a starting point. If there is something available it would save considerable time and effort since I would not need to reinvent the wheel. I recall seeing a small TCP proxy written in Delphi back in 2003/2004, but seem to have lost track of the link.
Are you looking for a socks proxy implementation? If not, then just start with a server (http would most likely be a good start) and build into it the ability to process your inbound XML data packet, and make the appropriate calls. Something like the Synapse framework would make that a fairly simple project. If you grab Synapse, get the latest version from SVN. It supports all of the latest versions of Delphi.
There is a httpproxy demo for synapse available, that might help if your wanting to implement something more traditional. A good starting http server example is also available.
IPWorks from nSoftware should be considered as a commercial alternative to Synapse. They also have some Biztalk adapters available.
I've used both Synapse and IPWorks, and they are both quite good. I haven't used the referenced BizTalk adapters.
BizTalk Adapters
IPWorks

Resources