taskencoder.java

来自「利用Java Socket写的一段通讯协议」· Java 代码 · 共 43 行

JAVA
43
字号
package com.ict.netcom2.trash;

import java.io.*;

public class TaskEncoder {

    public static byte[] encodeHttpRefTask(long testTimes, int port,
    		int interval, int protoType, String url) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);        
        try {        	
            dos.writeInt((int)(testTimes));
            dos.writeShort(url.length());
            dos.writeShort(port);
            dos.writeShort(interval);
            dos.writeShort(protoType);
            dos.writeBytes(url);
            dos.close();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return baos.toByteArray();
    }
    
    public static byte[] encodePasvEth() {
    	byte[] b= {1, 0, 1, 0, 0, 0, 0, 2, 60, 0, 1, 2, 3, 4, 5};
    	return b;
    }

    public static void main(String[] args) {
    	//long l = 0x0ffffffffl;
    	//char c = 0xffff;
    	
    	byte[] b = encodeHttpRefTask(
    			0x0ffffffffl, 0x50, 0x0ffff, 0x0ffffff, "www.google.com");
    	
    	for (int i=0; i<b.length; i++)
    		System.out.println((int)b[i]);   	
    	
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?