0

我试图通过网络连接发送 iso8583 数据,目前当我发送数据时,它在 TCP 查看器中显示为一个长字符串

但它应该看起来像这样

0000(0000)  30 38 30 30 82 38 00 00  00 00 00 00 04 00 00 00   0800.8..........
0016(0010)  00 00 00 00 30 38 32 34  31 30 35 31 30 30 31 33   ....082410510013
0032(0020)  35 31 30 30 31 33 35 31  30 30 30 38 32 34 33 30   5100135100082430
0048(0030)  31                                                 1

我发送数据的代码

Socket plug = new Socket(Config.getServerIP(), Config.getServerPort());
DataInputStream In= new DataInputStream(plug.getInputStream());
PrintWriter Out = new PrintWriter(plug.getOutputStream());

String Indata, Outdata;
Outdata =" ";
Indata = "NOTHING";

while (!Outdata.equals("Bye"))
{
  Outdata=message;
  Out.write(Outdata);
  Out.flush();

  if (!Outdata.equals("Bye"))
  {
    Indata=In.readLine();
    System.out.println(Indata);
  }
}
In.close();
Out.close();

数据是否必须以特定方式发送?非常感谢任何帮助。

4

1 回答 1

1

It turns out that the problem was that i had to write the output using a byte array of integers, this in turn shows in TCP viewer as Hex data, the next issue i faced was that any integer in the byte array over 128 was causing an overflow to by pass that i had to use the following methods

Socket server = new Socket(Config.getServerIP(), Config.getServerPort());
bytes = packData(bytes);
    server.getOutputStream().write(bytes, 0, bytes.length);

then the packData method

static byte[] packData(byte[] data) {
    int len = data.length;
    byte buf[] = new byte[len + 2];
    buf[0] = (byte) (len >> 8 & 255);
    buf[1] = (byte) (len & 255);
    System.arraycopy(data, 0, buf, 2, len);
    return buf;
}

Hope this helps someone

于 2013-08-28T09:42:33.510 回答