当前位置:网站首页>json tobean
json tobean
2022-06-29 06:46:00 【inspire121】














































Insert a code chip here
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Date;
import static Code_conversion.bytesToHexString;
public class Receiving_message_Server extends Thread {
public static ArrayList<Socket> sockets = new ArrayList<Socket>();
private Socket_data_service socket_data_service = new Socket_data_serviceimpl();
private Socket server;
private ServerSocket serverSocket;
public Receiving_message_Server() {
}
public Receiving_message_Server(int port) throws IOException {
serverSocket = new ServerSocket(port);
}
public void run() {
while (true) {
try {
System.out.println(" Waiting for remote connection .....");
server = serverSocket.accept(); // Blocking the listening port waiting for the requested connection
sockets.add(server);
System.out.println(" Remote host address :" + server.getRemoteSocketAddress());
System.out.println(" Connection time :" + new Date());
InputStream in = server.getInputStream(); // Get the stream sent by the client
BufferedInputStream bis = new BufferedInputStream(in); // Stream store buffer
DataOutputStream dos = new DataOutputStream(out); // Get buffer stream data
byte[] bytes = new byte[1]; // Read one at a time byte
String ret = "";
while (dis.read(bytes) != -1) {
ret += bytesToHexString(bytes) + " "; // Call byte conversion 16 Base string method
if (dis.available() == 0) {
// A request
System.out.println(" Received message data : " + ret);
ret = "";
}
}
in.close();
dos.close();
bis.close();
server.close(); // Close the connection
} catch (IOException e) {
e.printStackTrace();
break;
}
}
}
public static void main(String[] args) {
int port = 8888; // Listening port
try {
Thread t = new Receiving_message_Server(port); // Thread initialization
t.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Insert a code chip here
public class Code_conversion {
/**
* Binary conversion 16 Base string
* @param bytes
* @return
*/
public static String bytesToHexString(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
/***
* 16 Binary string conversion
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
}
边栏推荐
- 关于端口转发程序的一点思考
- Installing modules in pycharm
- [C language] flexible array
- Li Kou daily question - day 30 -1281 Difference of sum of bit product of integer
- Part 63 - interpreter and compiler adaptation (II)
- Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future
- Failure: unable to log in to "taxpayer equity platform"
- Hyperledger Fabric 2. X custom smart contract
- Pytest (7) -yield and termination function
- UVM验证平台
猜你喜欢

Longest substring between two identical characters of leetcode simple question

融入STEAM教育的劳动技能课程

How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)

Li Kou today's question -324 Swing sort II

Print Yanghui triangle

Service grid ASM year end summary: how do end users use the service grid?

The generation of leetcode simple questions each character is an odd number of strings

What are the uses of wireless pressure collectors?

Observer mode vs publish subscribe mode

2022.02.15 - 240. Lucky number in matrix
随机推荐
Baidu applet automatically submits search
Annual inventory review of Alibaba cloud's observable practices in 2021
package.json的所有配置项及其用法,你都熟悉么
Rearrangement string of leetcode simple question
MySQL learning notes
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
Implementation of queue
[deep learning] - maze task learning I (to realize the random movement of agents)
[c language] [sword finger offer article] - print linked list from end to end
C language pointer to function
Hyperledger Fabric 2. X custom smart contract
Leetcode simple problem building arrays with stack operation
UVM验证平台
2022.02.14
目标检测——使用yolov6进行视频推理
Analytic hierarchy process
Single application and microservice application
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function
Clickhouse data type