Содержание
- 2. References www.msdn.microsoft.com/library .Net Development/.Net Framework SDK/ .Net Framework/Reference/ClassLibrary/ System.Net.Sockets http://www.dotnetjunkies.com/quickstart/howto/doc/TCPUDP/DateTimeClient.aspx C# NetworkProgramming, Richard Blum, Sybex, 2003
- 3. What are Sockets? Sockets provide a common interface to the various protocols supported by networks. They
- 4. Socket Logical Structure
- 5. How do Sockets Function? There are several modes of operation available for sockets. A very common
- 6. Socket Client, Server, and Listener
- 7. Client/Server Configuration
- 8. Socket Data Transfer The receiving socket, either client or server, has a buffer that stores bytes
- 9. Non-Blocking Communication
- 10. Basic .Net Network Objects TCPListener TCPListener(port) AcceptTcpClient() AcceptSocket() Start() Stop() Socket Send(byte[], size, socketFlags) Receive(byte[], size,
- 11. More Network Programming Objects TCPClient TCPClient() Connect(IPAddress, port) GetStream() Close() NetworkStream NetworkStream(Socket) Read(byte[], offset, size) Write(byte[],
- 12. Simple Socket Client TcpClient tcpc = new TcpClient(); Byte[] read = new Byte[32]; // read buffer
- 13. Simple Socket Server TcpListener tcpl = new TcpListener(2048); // listen on port 2048 tcpl.Start(); while (true)
- 16. Multi-threaded Server If we want to support concurrent clients, the server must spawn a thread for
- 17. Define Thread’s Processing class threadProc { private Socket _sock = null; public threadProc(Socket sock) { _sock
- 18. Server Spawns Threads to Handle New Clients with threadProc.proc() // listen on port 2048 TcpListener tcpl
- 19. Clients now Wait for Server to Complete // Try to connect to the server tcpc.Connect(server, 2048);
- 20. Talk Protocol The hardest part of a client/server socket communication design is to control the active
- 21. Bilateral Channel Talk-Listen Protocol
- 22. Message Length Another vexing issue is that the receiver may not know how long a sent
- 23. Message Framing There are three solutions to this problem: Use fixed length messages – rarely useful
- 24. They’re Everywhere Virtually every network and internet communication method uses sockets, often in a way that
- 26. Скачать презентацию