Network-Socket Related (1)

zhaozj2021-02-16  49

TcpClient:

Main method:

Connect (IpendPoint), Connect (iPaddress, Port), Connect (String DNSName, Port)

The parameters of the constructor are the same, but the parameter specifies the information.

NetworkStream getStream (); A network stream that sends and receives data to the network, using its WRITE and READ methods to send and receive data, WRITE and READ are blocking methods.

TCPListener:

Main method:

Constructor: TCPListener (IpendPoint), TCPListener (iPaddress, Port)

START (), STOP (): Listening Request. If there is, the request will be queued and continue to listen until the STOP method is called. If the queue is received, the connection request will be received after the maximum value reaches the maximum value, will trigger a socketException.

Accepttcpclient (), Acceptsocket (): Removes the connection from the incoming connection queue. The AccepttcpClient method removes the connection from the queue and returns TCPClient. ACCEPTSOCKET Method Returns Socket. If you only need basic blocking synchronization I / O, AcceptTCPClient can be used. To make more detailed behavior, use Acceptsocket.

PENDING (): Determines if there is a connection available in the column.

UDPCLIENT:

Main method:

Connect (IpendPoint), Connect (IpadDress, Port): Create a default remote host with the specified network endpoint

If the Connect method is called, any datagram that arrives from the address other than the specified default address will be discarded. You cannot use this method to set the default remote host to broadcast addresses unless you use the following methods: Inheriting from UDPClient, using the client method to get the underlying socket, and set the socket option to socketoptionname.broadcast.

However, if IPAddress.Broadcast is specified when the Send method is called, the data can be broadcast to the default broadcast address: 255.255.255.255. If the application requires better control for the broadcast address, you can also recover to use the Socket class.

The parameters of the constructor are the same, but the parameter specifies the information.

JoinmulticastGroup (iPaddress MulticastAddr): Add UDPClient to multiple broadcast groups.

DROPMULTICASTGROUP (): Exit Multi-Broadcasting Group

Public Byte [] received (Ref iPndPoint Remoteep); Returns UDP Data Licenament sent by the remote host

Send: Send UDP Data Text to Remote Host

About multiple broadcasts:

JoinmulticastGroup methods Book UDPCLIENT to multiple broadcast groups that specify iPaddress. After calling this method, the base Socket sends the Internet Group Management Protocol (IGMP) package to the router and requests a member of the multi-channel broadcast group. The range of multiple broadcast addresses ranges from 224.0.0.0 to 239.255.255.255. If you don't support multiple broadcasts, or the router does not support multiple broadcasts, the socketException is triggered. UDPClient has become a member of the multi-channel broadcast group, it is possible to receive multiple broadcast data sent to the specified iPaddress, but do not need to be a multi-channel broadcast group, you can send the datagram to multiple broadcast IP addresses. You must create udpclient using multiple broadcast port numbers, otherwise the multi-channel broadcast datagram will not be received. Don't call the Connect method before calling the JoinMultativeGroup method, otherwise the Receive method will not work - see the UDPCLIENT method. ? ? ? NOT

Before you join multiple broadcast groups, make sure the UDP socket has been bound to the port or end. To this end, a constructor of the receiving port or end point is required to be called.

==========

IP version 4 address uses 32-bit specified network addresses. These bits are divided into four eight bytes for Class Class Class Class 2555.255.255.0. When a decimal number is represented, these four eight bytes constitute familiar four-part representations, such as 192.168.100.2. The first two eight-bit bytes (192.168 in this example) constitute the network number; the third eight-bit byte (100) defines the subnet; the last eight-bit byte (2) is the host identifier.

All bits of the IP address are set to 1 (ie 255.255.255.255) may constitute a limited broadcast address. Sending UDP Data Libaration to this address to pass messages to any host on the broadcast network. Since the router does not forward the message sent to this address, only the hosts on the connected network can see these broadcasts.

By setting all the bits of the partial address to 1, the broadcast can be oriented to a particular network portion. For example, to send a broadcast to all hosts on the network identified by the IP address of 192.168, all hosts are set to 1, such as 192.168.255.255. To limit the broadcast to a single subnet, only the host part is set to 1, such as 192.168.100.255.

The UDPCLIENT class can broadcast address to any network broadcast address, but it cannot listen to the broadcast sent to the network. You must use the Socket class to listen to online broadcasting

转载请注明原文地址:https://www.9cbs.com/read-20663.html

New Post(0)