wireshark中抓到包,用java发给本地测试程序

package com.example.demo;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;

public class SocketTest {

    public static void main(String[] args) throws Exception{
    Socket socket = new Socket("127.0.0.1", 12313);//接收方ip地址,端口号
    OutputStream out = socket.getOutputStream();
    String dataStr="";//wireshark里面抓到的数据包
        byte[] bytes = Hex2Byte(dataStr);
        out.write(bytes);
        out.flush();
    }
    public static float byteArrayToFloat(byte[] v) {
        ByteBuffer bb = ByteBuffer.wrap(v);
        FloatBuffer fb = bb.asFloatBuffer();
        return fb.get();
    }


    public static byte[] Hex2Byte(String inHex) {

        String[] hex = inHex.split("(?<=\\G.{2})");
        //String[] hex=inHex.split(" ");//将接收的字符串按空格分割成数组
        byte[] byteArray=new byte[hex.length];

        for(int i=0;i

你可能感兴趣的:(wireshark,java,python)