Send message:
Static Void Main ( String [] ARGs) {udpclient = New Udpclient (addressfamily. InterNetwork); ipendpoint broadcastip = New Ipendpoint (IPaddress. Broadcast, 4534 ); Int I = 0 ; While ( True ) {I ++ ; Byte [] B = encoding. utf8.getbytes ( " I am broadcasting messages " + I); udpclient. Send (B, B. length, broadcastip); console. writeline (I); system. Threading. thread. Sleep ( 1000 );} // Udpclient. Close (); // Console. writeline ("done "); // Console. Read (); }
Receive message:
Static Void Main ( String [] ARGs ){ Try {Udpclient receiveudpclient = New Udpclient ( 1 ); Ipendpoint localip =New Ipendpoint (IPaddress. Any, 0 ); While ( True ){ Byte [] R = receiveudpclient. Receive ( Ref Localip); console. writeline (encoding. utf8.getstring (R ));}} Catch (Exception ex) {console. writeline (ex. Message +Ex. stacktrace );}}