My topic here went a little bit off topic, so I want to open a separate one to isolate my question.
I still have very little knowledge about networking, but I managed to create a simple TCP server and client application, what is working quite well. But as I wanted to introduce some new features (at the moment server and client only communicates with JSON messages and now I also want to transfer files), I faced some conecptual problems in my code.
In the other thread and by googling I figured out, that TCP only uses one stream with one way from client to server and one way from server to client. If I will send data, it will be queued in a buffer and the other side will order this data in the same way it was sent from the one side.
So now my problem is, that if I introduce a way to send bigger data from the server to the client, this will block my whole application: In the meantime there is no way to receive other messages from the server.
I now heard about "multiplexing" and I found this thread, but unfortunately there are no real informations I could use. The only information I can find in the internet about multiplexing is about HTTP/2. It seems, that this multiplexing really allows sending data at the same time as I would need in my case. But unfortunately I am not able to understand the multiplexing part of the code in swift-nio-http2 or swift-nio-ssh.
I am unsure, what would be the best now:
Trying to implement any kind of multiplexing in my own code (but how?) or just using multiple connections? My other idea (I didn't try that yet) was to open multiple connections at the same time, then I can use one main connection for all the simple and small data and one or more other connections for transferring files. But then this leads me to another question: Every user in my applications authorizes himself with username and password. I would then have two possibilities: Option a) Open up a given number of seperate connections when authorizing at the beginning (so I would have for example 4 additional connections for file transfers) or option b) I open up one main connection at the beginning and the client gets an authentification token, he can use when opening separate connections for file transfer.
Then I also could switch my whole project to HTTP, I could maybe create a REST API. But in this case the client would need to connect for every request to the server, every time I would need a TLS handshake and I have the bad feeling, that this would slow down everything (that was the initial reason, why I use a permanent TCP connection).
I know, that my question has to do a lot about the conception of my application. But I had to write all those, because I wanted to demonstrate my problem leading in a simple question: Is there an easy way to use multiplexing when using a ClientBootstrap
and a ServerBootstrap
?