?? dwstate.java
字號:
import java.net.*;
public class DWState {
public static void main(String[] args) {
// TODO Auto-generated method stub
String ip = "192.168.10.199";
int port = 5000;
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(ip);
} catch (Exception e) {
// TODO: handle exception
System.exit(1);
}
DatagramSocket dsock = null;
try {
dsock = new DatagramSocket();
String line = null;
char STX = 0x02;
char ETX = 0x03;
String MSG = "on";
String SNDMSG = STX + MSG + ETX;
DatagramPacket sendPacket = new DatagramPacket(SNDMSG.getBytes(), SNDMSG.getBytes().length, inetAddress, port);
dsock.send(sendPacket);
byte[] buffer = new byte[200];
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 + -