67,550
社区成员




try {
int port = 7777;
byte[] msg = chattext.getText().getBytes();
// Get the internet address of the specified host
InetAddress address = InetAddress.getByName("124.126.176.80");//my pc`s ip adress
// Initialize a datagram packet with data and address
DatagramPacket packet = new DatagramPacket(msg, msg.length,
address, port);
packet.getPort();
// Create a datagram socket, send the packet through it, close it.
DatagramSocket dsocket = new DatagramSocket();
dsocket.send(packet);
dsocket.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
int port = 7777;
InetAddress address = InetAddress.getLocalHost();
DatagramSocket dsocket = new DatagramSocket(port, address);
byte[] buffer = new byte[65000];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
// Now loop forever, waiting to receive packets and printing them.
while (true) {
dsocket.receive(packet);
String longtex=new String(buffer, 0, packet.getLength());
..............