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














































Insérer un morceau de code ici
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("Attendez la connexion à distance.....");
server = serverSocket.accept(); // Blocage du port d'écoute en attente d'une connexion demandée
sockets.add(server);
System.out.println("Adresse de l'hôte distant:" + server.getRemoteSocketAddress());
System.out.println("Temps de connexion:" + new Date());
InputStream in = server.getInputStream(); // Obtenir le flux envoyé par le client
BufferedInputStream bis = new BufferedInputStream(in); // Tampon de stockage de flux
DataOutputStream dos = new DataOutputStream(out); // Obtenir les données du flux tampon
byte[] bytes = new byte[1]; // Lire un à la foisbyte
String ret = "";
while (dis.read(bytes) != -1) {
ret += bytesToHexString(bytes) + " "; // Conversion des octets d'appel 16 Méthode de chaîne décimale
if (dis.available() == 0) {
//Une demande
System.out.println(" Réception des données du message : " + ret);
ret = "";
}
}
in.close();
dos.close();
bis.close();
server.close(); // Fermer la connexion
} catch (IOException e) {
e.printStackTrace();
break;
}
}
}
public static void main(String[] args) {
int port = 8888; // Port d'écoute
try {
Thread t = new Receiving_message_Server(port); // Initialisation du thread
t.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Insérer un morceau de code ici
public class Code_conversion {
/**
* Conversion binaire16Chaîne décimale
* @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 Conversion de chaînes binaires en binaires
* @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;
}
}
边栏推荐
- How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
- Test Development - ten years of sharpening one sword (VII) interface test tool postman
- MySQL learning notes
- Configuring the flutter development environment
- 2022.02.15
- Venn diagram proportional and color shading with semi transparency
- What should I learn before learning programming?
- Principle of screen printing adjustment of EDA (cadence and AD) software
- Hyperledger Fabric 2. X custom smart contract
- 2022.02.15 - 240. Lucky number in matrix
猜你喜欢

作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!

Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future

关于DDNS

Clickhouse data type

Internet enterprises need CRM software to help

Teach you how to develop your own NPM package (publish to the NPM official website)

Fault: ntfrs warning log for id13562

Fault: NetBt log for id4321

What is the "danksharding" of V God Kop on Valentine's day?

Why are keys unordered in golang map
随机推荐
Why are keys unordered in golang map
UVM验证平台
JDBC | Chapter 5: closing and releasing JDBC connection resources
AIRNET notes 1
Browser local storage
VerilogA——动态比较器
Longest substring between two identical characters of leetcode simple question
Failure: unable to log in to "taxpayer equity platform"
Rearrangement string of leetcode simple question
Li Kou today's question -324 Swing sort II
[deep learning] - maze task learning I (to realize the random movement of agents)
Some high-level usage of localstorage
What are the uses of final?
Multithreading tool class completabilefuture
RedisTemplate处理hash整数类型的问题解析
What are the uses of wireless pressure collectors?
Ribbon service invocation and load balancing
Implementation of queue
Share 10 interview questions related to JS promise
Clickhouse data type