中国联通SGIP协议1.2版本C#实现
实现了几个方法:
Bind 建立连接
Submit MT
Deliver MO
Unbind 断开连接
Report 报告
代码使用反射实现,不是很完善,有待改进
在BaseModule中(没有包含在源代码中)申明了一个Delegate 输出调试信息的,申明如下
public delegate void DelegateSocketInformation(String str);
发送代码中SendUint和ReadUint写死了
protected uint ReadUint(Socket sock)
{
byte[] bArray = new byte[4];
if (sock.Receive(bArray) != 4)
{
throw new Exception("读取整数错误,读取字节数不等于4");
}
uint nValue = 0;
nValue ^= bArray[0];
nValue = nValue << 8;
nValue ^= bArray[1];
nValue = nValue << 8;
nValue ^= bArray[2];
nValue = nValue << 8;
nValue ^= bArray[3];
return nValue;
}
private int WriteUint(System.Net.Sockets.Socket socket, uint nValue)
{
byte[] bArray = new byte[4];
bArray[3] = (byte)(nValue & 0xFF);
bArray[2] = (byte)((nValue >> 8) & 0xFF);
bArray[1] = (byte)((nValue >> 16) & 0xFF);
bArray[0] = (byte)((nValue >> 24) & 0xFF);
return socket.Send(bArray);
}
附件为实现源代码
Bind 建立连接
Submit MT
Deliver MO
Unbind 断开连接
Report 报告
代码使用反射实现,不是很完善,有待改进
在BaseModule中(没有包含在源代码中)申明了一个Delegate 输出调试信息的,申明如下
public delegate void DelegateSocketInformation(String str);
发送代码中SendUint和ReadUint写死了
protected uint ReadUint(Socket sock)
{
byte[] bArray = new byte[4];
if (sock.Receive(bArray) != 4)
{
throw new Exception("读取整数错误,读取字节数不等于4");
}
uint nValue = 0;
nValue ^= bArray[0];
nValue = nValue << 8;
nValue ^= bArray[1];
nValue = nValue << 8;
nValue ^= bArray[2];
nValue = nValue << 8;
nValue ^= bArray[3];
return nValue;
}
private int WriteUint(System.Net.Sockets.Socket socket, uint nValue)
{
byte[] bArray = new byte[4];
bArray[3] = (byte)(nValue & 0xFF);
bArray[2] = (byte)((nValue >> 8) & 0xFF);
bArray[1] = (byte)((nValue >> 16) & 0xFF);
bArray[0] = (byte)((nValue >> 24) & 0xFF);
return socket.Send(bArray);
}
附件为实现源代码