Download presentation
Presentation is loading. Please wait.
Published byHerbert Powell Modified over 8 years ago
1
Concurrent TCP servers
2
The basic idea 1 client = 1 task. The task is alive as long until the connection is closed The task closes the connection
3
Why make servers concurrent? Concurrency One server can service several clients at the same time. One client does not have to wait for another client to finish… No waiting for I/O Some servers (like HTTP and file servers) read files. Reading a file takes a lot of time (compared to other operations) Robustness 1 One buggy/evil (or just slow) client cannot “take over” the server Example: The client makes a connection, but never sends a request Robustness 2 An error in the handling of a client, does not affect the handling of other clients.
4
Concurrent TCP servers: C# task Server = New TcpListener(host, port) Server.Start(); While (true) Client = server.AcceptTcpClient(); Task.Run(() => DoIt(client)); DoIt(client) gives service to this client.
5
Concurrent TCP servers: C# helper class Sometimes Task.Run(…) is to simple … Make a helper class to handle the request DoIt() is implemented in the helper class Parameters are handed to the helper class through its constructor Server = New TcpListener(host, port) Server.Start(); While (true) Client = server.AcceptTcpClient(); Helper helper = new Helper(client, other parameters); Task.Run(() => helper.DoIt());
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.