MCPcopy Create free account
hub / github.com/ZTFtrue/My-note / sendData

Method sendData

java/SendHexDataByUDP.java:40–56  ·  view source on GitHub ↗
(String data, int port, String... hosts)

Source from the content-addressed store, hash-verified

38 }
39
40 public void sendData(String data, int port, String... hosts) {
41 try {
42 mSocket = new DatagramSocket();
43 for (String host : hosts) {
44 InetSocketAddress address = new InetSocketAddress(host, port);
45 byte[] sendData = hexStrToByteArrs(data);
46 DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, address);
47 mSocket.send(sendPacket);
48 }
49 } catch (Exception e) {
50 e.printStackTrace();
51 } finally {
52 if (mSocket != null) {
53 mSocket.close();
54 }
55 }
56 }
57
58 /**
59 * 将十六进制的字符串转换成字节数组

Callers 1

onClickMethod · 0.95

Calls 1

hexStrToByteArrsMethod · 0.95

Tested by

no test coverage detected