Java SMPP库从头开始

时间:2013-09-01 14:59:29

标签: java sockets bytearray smpp pdu

我在某种程度上是java的新手,我想做的是通过ActiveXperts提交一系列十六进制值和smpp模拟器。

但是使用下面的代码,我甚至无法看到数据通过wireshark发送到模拟器端口,这意味着我做错了。

我从http://docs.nimta.com/smppv50.pdf获得了一系列十六进制值。所以他们应该有一个有效的pdu_header和pdu_body。然而,数据甚至没有出去请告诉我在java中错过了哪些步骤来提交数据。

public class Main {

/**
 * @param args the command line arguments
 */
private static byte[] ba = {0x00, 0x00, 0x00, 0x2F
        ,0x00, 0x00 ,0x00, 0x02
        ,0x00 ,0x00 ,0x00, 0x00
        ,0x00, 0x00,0x00 ,0x01
        ,0x53 ,0x4D, 0x50, 0x50
        ,0x33 ,0x54, 0x45 ,0x53
        ,0x54, 0x00, 0x73, 0x65
        ,0x63, 0x72, 0x65, 0x74
        ,0x30, 0x38, 0x00, 0x53
        ,0x55, 0x42, 0x4D, 0x49
        ,0x54, 0x31, 0x00 ,0x50
        ,0x01, 0x01, 0x00};
public static void main(String[] args) throws IOException {
    // TODO code application logic here

    try {
        Socket socket = new Socket("127.0.0.1", 2775);
        System.out.print("Connected");
        OutputStream out = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(out);
        for (int i=0; i< ba.length; i++){
            try {
                out.write(ba[i]);
            }catch  (Exception e){
                System.err.println("Don't know about host: taranis.");
            }
        }
        out.flush();
        out.close();

    } catch (UnknownHostException e) {
        System.err.println("Don't know about host: taranis.");
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Couldn't get I/O for "
                           + "the connection to: taranis.");
        System.exit(1);
    }


}

}

0 个答案:

没有答案