简体   繁体   English

Java-通过ISO8583通过网络发送数据

[英]java- Sending data over network for iso8583

Im trying to send iso8583 data over a network connection, currently when i send the data it is showing in TCP viewer as one long string 我正在尝试通过网络连接发送iso8583数据,当前当我发送数据时,它在TCP查看器中显示为一个长字符串

but it should look like this 但它应该看起来像这样

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

my code for sending the data 我发送数据的代码

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();

Does the data have to be sent in a specific way? 数据是否必须以特定方式发送? Any help much appreciated. 任何帮助,不胜感激。

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 事实证明,问题在于我必须使用整数字节数组写入输出,这反过来又在TCP查看器中显示为十六进制数据,我面临的下一个问题是字节数​​组中超过128的任何整数都导致溢出到必须使用以下方法

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

then the packData method 然后是packData方法

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 希望这可以帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM