19 lines
513 B
Java
Raw Normal View History

2015-05-05 11:20:13 -07:00
//: network/Dgram.java
2015-05-29 14:18:51 -07:00
// <20>2015 MindView LLC: see Copyright.txt
2015-05-05 11:20:13 -07:00
// A utility class to convert back and forth
// Between Strings and DataGramPackets.
import java.net.*;
public class Dgram {
public static DatagramPacket toDatagram(
String s, InetAddress destIA, int destPort) {
2015-05-31 18:34:12 -07:00
byte[] buf = s.getBytes();
return new DatagramPacket(buf, buf.length,
2015-05-05 11:20:13 -07:00
destIA, destPort);
}
public static String toString(DatagramPacket p){
2015-05-31 18:34:12 -07:00
return
2015-05-05 11:20:13 -07:00
new String(p.getData(), 0, p.getLength());
}
} ///:~