Y
yj3385
Unregistered / Unconfirmed
GUEST, unregistred user!
提供了由C写的结构,我用delphi写的连接和身份验证过程,但每次身份验证给我返回的结果都是系统时间校正
IP:218.20.111.70
port:8100
USR/PW:m / m
#define MAX_FRAMESIZE 32768
//帧头
typedef struct
{
int id; //值固定为 8888
WORD type; //数据帧类型,取值见下面枚举类型MAIN_CLIENT_FRAMES_TYPES
WORD wDataSize; //数据帧字节长度(除帧头)
}FRAME_HEAD;
//帧类型
enum MAIN_CLIENT_FRAMES_TYPES
{
FRM_SYSTEM_TIME =1, //系统时间设置
FRM_DYNAMIC_DATA = 2, //动态数据传输
FRM_LOGIN_APPLY = 3, //用户身份验证
FRM_LOGIN_REPLY =4, //用户身份验证应答
FRM_HISTORY_APPLY =5, //历史数据申请
FRM_HISTORY_REPLY =6, //历史数据应答
FRM_CODE_APPLY = 7, //申请码表
FRM_CODE_REPLY = 8, //申请应答
FRM_SELECTED_QUOT_APPLY =9, //行情申请
FRM_SELECTED_QUOT_REPLY =10, //行情应答
FRM_PING_APLLY = 11, //ping
FRM_PING_REPLY = 12, //ping应答
FRM_MONITORQUOTE_APPLY = 13, //订阅市场的动态数据
FRM_DELETE_CODE = 14, //删除没用的码表
FRM_SUM_REPLY = 18, //下传各品种小计(原指数)量仓
};
//系统时间校正帧FRM_SYSTEM_TIME = 1(Server→Client)
// |FRAME_HEAD|SYSTEM_TIME|
typedef struct
{
WORD wYear;
WORD wMonth;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;// UMSC 系统同步时钟
}SYSTEM_TIME;
//动态数据传输帧FRM_DYNAMIC_DATA = 2(Server→Client)
// |FRAME_HEAD|DYNAMIC_DATA|WORD|DCE_PRICE_SEND|DCE_PRICE_SEND|...|
typedef struct
{
BYTE bySubFrameType; //值固定为88
}DYNAMIC_DATA;
typedef struct
{
BYTE MarketID;
WORD NameID;
DWORD dwOpenInterest; /*空盘量 */
DWORD dwVolume; /*成交量 */
DWORD dwTotalBidAmount; /*申买量总量: 监视用 */
DWORD dwTotalOfferAmount; /*申卖量总量: 监视用 */
DWORD open_interest_init;
WORD wOpen; /*开盘价 */
WORD wHigh; /*最高价 */
WORD wLow; /*最低价 */
WORD wNew; /*最新价 */
WORD wBid; /*申买价 */
WORD wOffer; /*申卖价 */
DWORD wBidAmount; /*申买量 */
DWORD wOfferAmount; /*申卖量 */
WORD wLastClose; /*昨收盘价 */
WORD wLastSettle; /*昨结算价 */
WORD wClose; /*收盘价 */
WORD wSettle; /*结算价 */
WORD arerrage;
short int Delta1;
short int Delta2;
CTime Time;
}DCE_PRICE_SEND;
//用户身份验证帧FRM_LOGIN_APPLY = 3(Client→Server)
// |FRAME_HEAD|Client_USER_CHECK|
typedef struct
{
char szUserName[12]; //用户名
char szPassWord[12]; //用户口令
}Client_USER_CHECK;
//用户身份验证应答帧FRM_LOGIN_REPLY = 4(Server→Client)
// |FRAME_HEAD|USER_ACCEPT|
typedef struct
{
BYTE byNum;
BYTE Right[16];
}USER_RIGHT; //功能预留byNum = 16,Right[0-15] = 1
typedef struct
{
BYTE LoginOK; //接受登录为1,拒绝登录为0
USER_RIGHT Right;
}USER_ACCEPT;
我用delphi7的indy控件写的,部分代码如下:
//帧头
type
TFRAME_HEAD = record
id : integer; //值固定为 8888
types : WORD; //数据帧类型,取值见下面枚举类型MAIN_CLIENT_FRAMES_TYPES
wDataSize : WORD; //数据帧字节长度(除帧头)
end;
//用户身份验证帧FRM_LOGIN_APPLY = 3(Client→Server)
TClient_USER_CHECK = record
szUserName : array[0..11] of Char;
szPassWord : array[0..11] of Char;
end;
//用户身份验证应答帧FRM_LOGIN_REPLY = 4(Server→Client)
TUSER_RIGHT = record
byNum : byte;
Right : array[0..15] of byte;
end;//功能预留byNum = 16,Right[0-15] = 1
TUSER_ACCEPT = record
LoginOK : byte;
Right : TUSER_RIGHT;
end;//功能预留byNum = 16,Right[0-15] = 1
//客户端请求结构
TClient_USER_Send = record
FRAME_HEAD : TFRAME_HEAD;
Client_USER_CHECK : TClient_USER_CHECK;
end;
//客户端接收结构
TClient_USER_Write = record
FRAME_HEAD : TFRAME_HEAD;
USER_ACCEPT : TUSER_ACCEPT;
end;
//系统时间校正帧FRM_SYSTEM_TIME = 1(Server→Client)
TSYSTEM_TIME = record
wYear : WORD;
wMonth : WORD;
wDay : WORD;
wHour : WORD;
wMinute : WORD;
wSecond : WORD;// UMSC 系统同步时钟
end;
//客户端接收时间
TClient_Read_TIME = record
FRAME_HEAD : TFRAME_HEAD;
SYSTEM_TIME : TSYSTEM_TIME;
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
IdTCPClient.Host := '218.20.111.70';
IdTCPClient.Port := 8100;
LbLog.Items.Add('正在连接 ...');
with IdTCPClient do
begin
try
Connect(5000);
try
except
LbLog.Items.Add('远程主机无响应!');
IdTCPClient.Disconnect();
end;
except
LbLog.Items.Add('无法建立到的连接!');
end;
end;
end;
procedure TForm3.Button2Click(Sender: TObject);
var
i : integer;
Arr : array of Char;
myrecord : TFRAME_HEAD;
myuser : TClient_USER_CHECK;
USER_RIGHT : TUSER_RIGHT;
USER_ACCEPT : TUSER_ACCEPT;
Client_USER_Send : TClient_USER_Send;
Client_USER_Write : TClient_USER_Write;
//时间校正帧
SYSTEM_TIME : TSYSTEM_TIME;
Client_Read_TIME : TClient_Read_TIME;
begin
myuser.szUserName[0] := 'm';
myuser.szPassWord[0] := 'm';
myrecord.id := 8888;
myrecord.types := 3;
myrecord.wDataSize := sizeof(myuser);
Client_USER_Send.FRAME_HEAD := myrecord;
Client_USER_Send.Client_USER_CHECK := myuser;
with IdTCPClient do
begin
if Connected then
begin
try
WriteBuffer(Client_USER_Send, sizeof(Client_USER_Send));
except
Memo1.Lines.Add('发送数据失败!');
IdTCPClient.Disconnect();
Memo1.Lines.Add('同主机 连接已断开!');
end;
try
ReadBuffer(Client_USER_Write, sizeof(Client_USER_Write));
//以下传回来系统时间验证
{
ReadBuffer(Client_Read_TIME, sizeof(Client_Read_TIME));
SYSTEM_TIME := Client_Read_TIME.SYSTEM_TIME;
LbLog.Items.Add(DateToStr(EncodeDate(SYSTEM_TIME.wYear, SYSTEM_TIME.wMonth, SYSTEM_TIME.wDay)));
}
except
Memo1.Lines.Add('接收数据失败!');
IdTCPClient.Disconnect();
Memo1.Lines.Add('同主机连接已断开!');
end;
edit1.Text := '接收成功';
end
else
begin
edit1.Text := '失去连接';
end;
end;
end;
IP:218.20.111.70
port:8100
USR/PW:m / m
#define MAX_FRAMESIZE 32768
//帧头
typedef struct
{
int id; //值固定为 8888
WORD type; //数据帧类型,取值见下面枚举类型MAIN_CLIENT_FRAMES_TYPES
WORD wDataSize; //数据帧字节长度(除帧头)
}FRAME_HEAD;
//帧类型
enum MAIN_CLIENT_FRAMES_TYPES
{
FRM_SYSTEM_TIME =1, //系统时间设置
FRM_DYNAMIC_DATA = 2, //动态数据传输
FRM_LOGIN_APPLY = 3, //用户身份验证
FRM_LOGIN_REPLY =4, //用户身份验证应答
FRM_HISTORY_APPLY =5, //历史数据申请
FRM_HISTORY_REPLY =6, //历史数据应答
FRM_CODE_APPLY = 7, //申请码表
FRM_CODE_REPLY = 8, //申请应答
FRM_SELECTED_QUOT_APPLY =9, //行情申请
FRM_SELECTED_QUOT_REPLY =10, //行情应答
FRM_PING_APLLY = 11, //ping
FRM_PING_REPLY = 12, //ping应答
FRM_MONITORQUOTE_APPLY = 13, //订阅市场的动态数据
FRM_DELETE_CODE = 14, //删除没用的码表
FRM_SUM_REPLY = 18, //下传各品种小计(原指数)量仓
};
//系统时间校正帧FRM_SYSTEM_TIME = 1(Server→Client)
// |FRAME_HEAD|SYSTEM_TIME|
typedef struct
{
WORD wYear;
WORD wMonth;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;// UMSC 系统同步时钟
}SYSTEM_TIME;
//动态数据传输帧FRM_DYNAMIC_DATA = 2(Server→Client)
// |FRAME_HEAD|DYNAMIC_DATA|WORD|DCE_PRICE_SEND|DCE_PRICE_SEND|...|
typedef struct
{
BYTE bySubFrameType; //值固定为88
}DYNAMIC_DATA;
typedef struct
{
BYTE MarketID;
WORD NameID;
DWORD dwOpenInterest; /*空盘量 */
DWORD dwVolume; /*成交量 */
DWORD dwTotalBidAmount; /*申买量总量: 监视用 */
DWORD dwTotalOfferAmount; /*申卖量总量: 监视用 */
DWORD open_interest_init;
WORD wOpen; /*开盘价 */
WORD wHigh; /*最高价 */
WORD wLow; /*最低价 */
WORD wNew; /*最新价 */
WORD wBid; /*申买价 */
WORD wOffer; /*申卖价 */
DWORD wBidAmount; /*申买量 */
DWORD wOfferAmount; /*申卖量 */
WORD wLastClose; /*昨收盘价 */
WORD wLastSettle; /*昨结算价 */
WORD wClose; /*收盘价 */
WORD wSettle; /*结算价 */
WORD arerrage;
short int Delta1;
short int Delta2;
CTime Time;
}DCE_PRICE_SEND;
//用户身份验证帧FRM_LOGIN_APPLY = 3(Client→Server)
// |FRAME_HEAD|Client_USER_CHECK|
typedef struct
{
char szUserName[12]; //用户名
char szPassWord[12]; //用户口令
}Client_USER_CHECK;
//用户身份验证应答帧FRM_LOGIN_REPLY = 4(Server→Client)
// |FRAME_HEAD|USER_ACCEPT|
typedef struct
{
BYTE byNum;
BYTE Right[16];
}USER_RIGHT; //功能预留byNum = 16,Right[0-15] = 1
typedef struct
{
BYTE LoginOK; //接受登录为1,拒绝登录为0
USER_RIGHT Right;
}USER_ACCEPT;
我用delphi7的indy控件写的,部分代码如下:
//帧头
type
TFRAME_HEAD = record
id : integer; //值固定为 8888
types : WORD; //数据帧类型,取值见下面枚举类型MAIN_CLIENT_FRAMES_TYPES
wDataSize : WORD; //数据帧字节长度(除帧头)
end;
//用户身份验证帧FRM_LOGIN_APPLY = 3(Client→Server)
TClient_USER_CHECK = record
szUserName : array[0..11] of Char;
szPassWord : array[0..11] of Char;
end;
//用户身份验证应答帧FRM_LOGIN_REPLY = 4(Server→Client)
TUSER_RIGHT = record
byNum : byte;
Right : array[0..15] of byte;
end;//功能预留byNum = 16,Right[0-15] = 1
TUSER_ACCEPT = record
LoginOK : byte;
Right : TUSER_RIGHT;
end;//功能预留byNum = 16,Right[0-15] = 1
//客户端请求结构
TClient_USER_Send = record
FRAME_HEAD : TFRAME_HEAD;
Client_USER_CHECK : TClient_USER_CHECK;
end;
//客户端接收结构
TClient_USER_Write = record
FRAME_HEAD : TFRAME_HEAD;
USER_ACCEPT : TUSER_ACCEPT;
end;
//系统时间校正帧FRM_SYSTEM_TIME = 1(Server→Client)
TSYSTEM_TIME = record
wYear : WORD;
wMonth : WORD;
wDay : WORD;
wHour : WORD;
wMinute : WORD;
wSecond : WORD;// UMSC 系统同步时钟
end;
//客户端接收时间
TClient_Read_TIME = record
FRAME_HEAD : TFRAME_HEAD;
SYSTEM_TIME : TSYSTEM_TIME;
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
IdTCPClient.Host := '218.20.111.70';
IdTCPClient.Port := 8100;
LbLog.Items.Add('正在连接 ...');
with IdTCPClient do
begin
try
Connect(5000);
try
except
LbLog.Items.Add('远程主机无响应!');
IdTCPClient.Disconnect();
end;
except
LbLog.Items.Add('无法建立到的连接!');
end;
end;
end;
procedure TForm3.Button2Click(Sender: TObject);
var
i : integer;
Arr : array of Char;
myrecord : TFRAME_HEAD;
myuser : TClient_USER_CHECK;
USER_RIGHT : TUSER_RIGHT;
USER_ACCEPT : TUSER_ACCEPT;
Client_USER_Send : TClient_USER_Send;
Client_USER_Write : TClient_USER_Write;
//时间校正帧
SYSTEM_TIME : TSYSTEM_TIME;
Client_Read_TIME : TClient_Read_TIME;
begin
myuser.szUserName[0] := 'm';
myuser.szPassWord[0] := 'm';
myrecord.id := 8888;
myrecord.types := 3;
myrecord.wDataSize := sizeof(myuser);
Client_USER_Send.FRAME_HEAD := myrecord;
Client_USER_Send.Client_USER_CHECK := myuser;
with IdTCPClient do
begin
if Connected then
begin
try
WriteBuffer(Client_USER_Send, sizeof(Client_USER_Send));
except
Memo1.Lines.Add('发送数据失败!');
IdTCPClient.Disconnect();
Memo1.Lines.Add('同主机 连接已断开!');
end;
try
ReadBuffer(Client_USER_Write, sizeof(Client_USER_Write));
//以下传回来系统时间验证
{
ReadBuffer(Client_Read_TIME, sizeof(Client_Read_TIME));
SYSTEM_TIME := Client_Read_TIME.SYSTEM_TIME;
LbLog.Items.Add(DateToStr(EncodeDate(SYSTEM_TIME.wYear, SYSTEM_TIME.wMonth, SYSTEM_TIME.wDay)));
}
except
Memo1.Lines.Add('接收数据失败!');
IdTCPClient.Disconnect();
Memo1.Lines.Add('同主机连接已断开!');
end;
edit1.Text := '接收成功';
end
else
begin
edit1.Text := '失去连接';
end;
end;
end;