IP
Multi-channel broadcast C #. NETHttp: // http://www.c-sharpcorner.com/introduction:
Currently, multi-point broadcast is widely used. With the increasing bandwidth and multimedia
Stream utilization, broadcast will become a widely used method in the near future.
What is IP multicast?
IP multicast is a broadband storage technology that can be used to solve information congestion on the network.
Send a single message stream to thousands of recipients at the same time. He is characterized by a single desire to spread without reverse signal.
This idea can be considered similar to broadcasting between satellites and television. A single satellite sends information to many receivers on the ground. Data Streams send information along the transmission path to the passing routers and hosts. At the same time, these routers and hosts can copy data streams, then, send messages to other routers and hosts. IP address multicast needs:
All routers passing through data streams in IP address multiplexing must be broadcast-enabled. For Internet
Broadcast, all transmission devices must be a member of MBONE (a multimedia skeleton structure that can transmit images globally. However, as more and more manufacturers develop routers that support IP broadcast, MBONE will gradually exit the historical stage.
System Requirements:
1. operating systems that support IP multicast, such as Windows2000, XP. Berkeley Sockets, Windows Sockets 2, and Apple Macintosh Open Transport all support IP multicast.
2 ... NET Framework API. microsoft. net Framework provides applications with hierarchical, scalable, and governed network services to access the Internet. Its namespace is System. net and System. net. sockets contains a variety of classes to develop a variety of network applications .. . Net class uses a layered structure that allows applications to access the network at different control levels. developers can choose to compile programs at different levels as needed, these levels cover almost all the needs of the Internet-from socket sockets to common requests/responses. More importantly, this layer can be expanded to meet the needs of continuous Internet expansion.
Here, I will use C # To provide an example to implement multi-channel IP address broadcast.
1. send data to a broadcast group
Because it is unidirectional transmission, there is no need to shake hands. We use UDP here.
// Create a socket Socket s = new Socket (AddressFamily. InterNetwork ,_
SocketType. Dgram ,_
Protocoltype. UDP); // address of addressfamily. Internetwork IP version 4. // Sockettype. dgram supports data packets, that is, messages with a fixed maximum length (usually very small) that are connectionless and unreliable. Messages may/may be lost or duplicated and may not be arranged in order upon arrival. A dgram-type socket does not need any connection before sending or receiving data, and can communicate with multiple hosts of the other party. // Sockettype implicitly indicates which protocoltype will be used in addressfamily. For example, if sockettype // is dgram, protocoltype is always UDP. When sockettype is stream, protocoltype is always // TCP. // The valid IP address range of multicast packets is 224.0.0.0 to 239.255.255.255. IPaddress IP = IPaddress. parse ("224.5.6.7"); S. setsocketoption (socketoptionlevel. IP ,_
Socketoptionname. addmembership ,_
New_multicastoption (IP); // socketoptionlevel parameter explanation:
// The IP socket option is applied to the IP socket.
// The Socket socket option is applied to the socket itself.
// The TCP socket option is applied to the TCP socket.
// UDP socket option applies to UDP socket.
// Socketoptionname. addmembership
// Addmembership adds an IP group member.
S. setsocketoption (socketoptionlevel. IP, socketoptionname. multicasttimetolive, 2 );
// Socketoptionname. multicasttimetolive IP multi-channel broadcast survival time.
Ipendpoint ipep = new ipendpoint (ipendpoint, 4567 );
S. Connect (ipep); // create the sent data abcdefghij
Byte [] B = new byte [10];
For (INT x = 0; x <B. length; X ++) B [x] = (byte) (x + 65); // send data
S. Send (B, B. length, socketflags. None); // close the socket
S. close (); 2. multi-channel broadcast receiving data program: we have sent the letter abcdefghij to the broadcast group 224.5.6.7 through port 4567. all listening programs will receive this set of data socket S = new socket (addressfamily. interNetwork, sockettype. dgram, protocoltype. UDP); // create a socketipendpoint ipep = new ipendpoint (IPaddress. any, 4567 );
S. BIND (ipep); // any IP that listens to port 4567 will receive the data IPaddress IP = IPaddress. parse ("224.5.6.7"); S. setsocketoption (socketoptionlevel. IP ,_
Socketoptionname. addmembership ,_
New multicastoption (IP, IPaddress. Any); // Add the socket to the broadcast group 224.5.6.7.byte [] B = new byte [1024];
S. Receive (B );
String STR = system. Text. encoding. ASCII. getstring (B, 0, B. Length );
Console. writeline (Str. Trim (); // we can receive any data sent by this broadcast group.
Author's Blog:Http://blog.csdn.net/enterlc/
Related Articles
Sendkeys
And SendmessagePrivate declare function sendmessage lib "user32.dll" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
Private declare function findwindow lib "user32.dll" alias "find0000wa" (byval lpclassname as string, byval lpwindowname as string) as long
Private declare function find1_wex lib "USER32" alias "find1_wexa" (byval hwnd1 as long, byval hwnd2 as long, byval lpsz1 as string, byval lpsz2 as string) as longfunction sqrx (byval X as double) as string 'calculates the square root (higher accuracy than VB double)
Dim temp as string, I as long, J as long
Shell "Calc. EXE", vbminimizednofocus 'Run Calculator
Temp = x & "y0.5 ="
For I = 1 to Len (temp)
Sendkeys mid (temp, I, 1), true' send the key message x (x ^ y) 0.5 =
Next
Temp = string (64, CHR (0 ))
I = findwindow (vbnullstring, "Calculator") 'window handle
J = find1_wex (I, byval 0 &, "edit", vbnullstring) 'edit box handle
Sendmessage J, & HD, Len (temp), byval temp send the edit box text to temp
SendKeys "% {F4}", True 'call ALT + F4 to close the calculator window
Sqrx = temp
End FunctionPrivate Sub commandementclick ()
Dim I As Integer
For I = 17 To 24
Debug. Print "sqrx (" & I & ") =" & sqrx (I)
Next
End Sub
Return Value:
Sqrx (17) = 4.1231056256176605498214098559741
Sqrx (18) = 4.2426406871192851464050661726291
Sqrx (19) = 4.3588989435406735522369819838596
Sqrx (20) = 4.4721359549995793928183473374626
SQL rx (21) = 4.582575694955840006588047193728
Sqrx (22) = 4.6904157598234295545656301135445
Sqrx (23) = 4.7958315233127195415974380641627
Sqrx (24) = 4.8989794855663561963945681494118