forked from patniemeyer/learningjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPulse.java
More file actions
21 lines (19 loc) · 687 Bytes
/
Copy pathPulse.java
File metadata and controls
21 lines (19 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//file: Pulse.java
import java.net.*;
import java.io.*;
public class Pulse {
public static void main( String [] argv ) throws IOException {
DatagramSocket s =
new DatagramSocket( Integer.parseInt(argv[0]) );
while ( true ) {
DatagramPacket packet =
new DatagramPacket( new byte [1024], 1024 );
s.receive( packet );
System.out.println( "packet length = "+packet.getData().length );
String message = new String( packet.getData(), "UTF-8" );
System.out.println( "Heartbeat from: "
+ packet.getAddress().getHostName()
+ " - " + message );
}
}
}