【发布时间】:2016-10-27 18:23:10
【问题描述】:
早安
我正在编写一个需要通过 ATS 软件与 Verifone vx820 ped 通信的应用程序。
在他们的文档中,为了传输数据,它指出:
我在 c# 中有一个示例说明如何做到这一点,这里是:
// Format of ATS telegram:
//
// +---------------------------- ... ---------------------------------+
// | xx | xx | xx | xx | Data |
// +---------------------------- ... ---------------------------------+
// Byte | 0 | 1 | 2 | 3 | 4 ...
// | |
// Field | -- Data Length -- | Data
//
// Data length is 4 bytes; network byte order (big-endian)
try
{
// Attempt to make TCP connection to ATS
Connect();
// Convert data length to network byte order...
int iLengthNetworkByteOrder = IPAddress.HostToNetworkOrder(Data.Length);
// ...then convert it to a byte array
byte[] DataLength = BitConverter.GetBytes(iLengthNetworkByteOrder);
// Construct the send buffer, prefixing the data with the data length as shown above
m_SendBuffer = new byte[DataLength.Length + Data.Length];
DataLength.CopyTo(m_SendBuffer, 0);
Data.CopyTo(m_SendBuffer, DataLength.Length);
// Signal the background thread there is data to send
m_eventSendDataAvailable.Set();
}
但是我正在构建它是 java。任何人都可以帮助我转换为 Java。 Java 中有没有简单的方法可以做到这一点?
有没有人用java构建了一个使用ATS的应用程序,有什么有用的我应该知道的
【问题讨论】:
-
DataOutputStream的原始写法都是大端的。
标签: java networking