Answer the question
In order to leave comments, you need to log in
How to keep connection between client and server in C#?
Good day, IT specialists!
My task is to write an update system for the software we develop. The software runs on an industrial computer based on Windows Embedded Standard 7. The system has to be written because there is no physical access to the computer at the working site. Therefore, all updates will have to be carried out via the local network from the operator's workstation.
The idea is this: write a remote file explorer. On the panel computer, start the server that will listen for incoming connections. On commands from the client application, the server will return lists of folders and files, delete them, send them to the client or receive new files from the client and add them to the specified paths.
Based on the article at the linkan asynchronous server was written. Because I am new to network programming, so I have a number of questions:
1) how to keep the connection between the client and the server?
Those. how it should look like so that the server creates a connection on request from the client and holds it while various information is being exchanged between them. In the synchronous version, I have a connection created every time the exchange starts, and ends when the exchange ends.
Example:
a) the client sends a file download request to the server
b) the server sends the file size
c) the client receives the file size and creates a byte array of the same size to accept the file
d) the server sends the byte array and ends the connection
e) the client receives this information into the previously created array, after which it writes it to disk to a file. What happens if the file size is larger than the array size? After all, the array is created in memory, and if the size of the transferred file is larger than the client's RAM, then it simply will not get into memory. How then to be?
As a result, it turns out that connections are constantly created and completed.
2) what is the best way to transfer files between client and server?
Since it's implemented now, I don't really like it. Those. the size of the file is passed first, and only then the file itself.
Here in this article from Habr, it seems like a good client-server architecture based on a shared library. But here everything seems to be in sync. Sorry if I blew stupidity, while there is not enough experience to write something like that.
Or maybe, in my case, an asynchronous server is not needed? There will be a maximum of 2 clients.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question