?? udpoff.java
字號:
import java.net.*;
public class UDPOff {
public static void main(String[] args) {
String ip = "192.168.10.199";
int port = 5000;
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(ip);
} catch (Exception e) {
System.exit(1);
}
DatagramSocket dsock = null;
try {
dsock = new DatagramSocket();
char STX = 0x02;
char ETX = 0x03;
String MSG = "off";
String SNDMSG = STX + MSG + ETX;
DatagramPacket sendPacket = new DatagramPacket(SNDMSG.getBytes(), SNDMSG.getBytes().length, inetAddress, port);
dsock.send(sendPacket);
System.out.println("SNDMSG: " + SNDMSG);
/**
byte[] buffer = new byte[100];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
dsock.receive(receivePacket);
String msg = new String(receivePacket.getData(), 0, receivePacket.getData().length);
System.out.println("輯滾肺 傈崔罐籃 藹 : " + msg.trim());
**/
} catch (Exception e) {
System.out.println(e);
} finally {
if (dsock != null)
dsock.close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -