Работа с сетевыми соединениями
Summary
The Microsoft .NET Framework provides a layered, extensible, and managed implementation of Internet services that can be quickly and easily integrated into your applications. Your applications can build on pluggable protocols to automatically take advantage of new Internet protocols, or they can use a managed implementation of the Windows socket interface to work with the network on the socket level.
Основные классы
Class | Description |
IPv6MulticastOption |
IrDAClient | Provides connection information, and creates client connection objects for opening and closing connections to a server. |
IrDADeviceInfo | Provides information about available servers and ports obtained by the client during a discovery query. |
IrDAListener | Places a socket in a listening state to monitor connections from a specified service or network address. |
LingerOption | Specifies whether a Socket will remain connected after a call to Close and the length of time it will remain connected, if data remains to be sent. |
MulticastOption | Contains IPAddress values used for joining and dropping multicast groups. |
NetworkStream | Provides the underlying stream of data for network access. |
Socket | Implements the Berkeley sockets interface. |
SocketException | The exception that is thrown when a socket error occurs. |
TcpClient | Provides client connections for TCP network services. |
TcpListener | Listens for connections from TCP network clients. |
UdpClient | Provides User Datagram Protocol (UDP) network services. |
See also:
System.Net.Sockets Namespace at MSDN
Основные операции
Уровень запроса/ответа
WebRequest req=WebRequrestFactory.Create("http://to.post.to.com");
Stream input=request.GetResponse().GetResponseStream();
// ... read from input stream
input.Close();
Уровень протокола
Создание клиента
TCPClient telnet = new TCPClient("telnet.host.com", 23);
Stream telnetStream = telnet.GetStream();
StreamReader output = new StreamReader( telnetStream );
StreamWriter input = new StreamWriter( telnetStream );
Создание сервера
TCPListener server = new TCPListener( 23 );
server.Start();
Socket accept = server.Accept();
Передача/прием данных
Обработка исключительных ситуаций
Рекомендации
Безопасность при сетевых соединениях
Links
--
AndreyUstyuzhanin - 07 Apr 2004