分享
 
 
 

SGIP的delphi原码

王朝delphi·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

在网上找了好长时间,也没有发现有SGIP的例子,伤感之余,终于做了一个Delphi6.0的SGIP例子

包含了一个服务端和一个客户端,协议共用,服务端为非阻塞长连接,客户端为阻塞短连接,

程序写的很乱,风格也很差,希望高手多多指教

dulcet99@163.com,dulcet99@sina.com

file://客户端

unit TestMain;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, ScktComp, StdCtrls, ExtCtrls, xy, winsock;

const

FV_SNumber=3053112345;

FV_LoginPass='hi';

FV_LoginName='hi';

FV_SPNumber='12345';

T_Tel='13000000000';

FV_corpID='12345';

T_msg='我在天空写下你的名字,没有被风带走';

type

TForm1 = class(TForm)

Memo1: TMemo;

Button1: TButton;

ClientSocket1: TClientSocket;

Button3: TButton;

Button4: TButton;

Button2: TButton;

Button5: TButton;

Button6: TButton;

Button7: TButton;

ServerSocket1: TServerSocket;

panel1: TPanel;

procedure Button2Click(Sender: TObject);

procedure Button1Click(Sender: TObject);

procedure Button6Click(Sender: TObject);

procedure Button5Click(Sender: TObject);

procedure Button3Click(Sender: TObject);

procedure Button4Click(Sender: TObject);

procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);

procedure Button7Click(Sender: TObject);

procedure ServerSocket1ClientRead(Sender: TObject;

Socket: TCustomWinSocket);

private

{ Private declarations }

public

{ Public declarations }

file://客户端协议定义

sHead: SGIPHead; file://消息头定义

sBind: XBind; file://连接请求验证

sBind_Resp: Bind_Resp; file://响应连接请求验证

sSubmit: XSubmit; file://SP->SMG提交短信

sSubmit_Resp: Submit_Resp; file://SMG响应SP提交的短信状态

sDeliver: XDeliver; file://SMG->SP提交短信

sDeliver_Resp: Deliver_Resp; file://SP响应SMG提交的短信状态

sReport: XReport; file://SMG->SP先前的短信状态

sReport_Resp: Report_Resp; file://响应命令执行状况

file://服务端协议定义

cHead: SGIPHead; file://消息头定义

cBind: XBind; file://连接请求验证

cBind_Resp: Bind_Resp; file://响应连接请求验证

cSubmit: XSubmit; file://SP->SMG提交短信

cSubmit_Resp: Submit_Resp; file://SMG响应SP提交的短信状态

cDeliver: XDeliver; file://SMG->SP提交短信

cDeliver_Resp: Deliver_Resp; file://SP响应SMG提交的短信状态

cReport: XReport; file://SMG->SP先前的短信状态

cReport_Resp: Report_Resp; file://响应命令执行状况

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button2Click(Sender: TObject);

begin

ClientSocket1.Active:=false;

if ClientSocket1.Active then

memo1.Lines.Add('客户端关闭失败')

else

memo1.Lines.Add('客户端关闭成功');

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

ClientSocket1.Active:=true;

if ClientSocket1.Active then

memo1.Lines.Add('客户端打开成功')

else

memo1.Lines.Add('客户端打开失败');

end;

procedure TForm1.Button6Click(Sender: TObject);

begin

ServerSocket1.Active:=true;

if ServerSocket1.Active then

memo1.Lines.Add('服务端打开成功')

else

memo1.Lines.Add('服务端打开失败');

end;

procedure TForm1.Button5Click(Sender: TObject);

begin

ServerSocket1.Active:=false;

if ServerSocket1.Active then

memo1.Lines.Add('服务端关闭失败')

else

memo1.Lines.Add('服务端关闭成功');

end;

procedure TForm1.Button3Click(Sender: TObject);

var

FV_Date1_S,FV_Date2_S:string;

str_i,SendSize:integer;

stream1:TWinSocketStream;

abc,bc:longword;

begin

stream1:=TWinSocketStream.Create(ClientSocket1.Socket,30000);

memo1.Lines.Add('-------------------向服务端发送BIND请求--------------------');

if not ClientSocket1.Active then

begin

memo1.Lines.Add('客户端没有打开');

exit;

end;

DateTimeToString(FV_Date1_S,'mmddhhnnss',now);

DateTimeToString(FV_Date2_S,'zzz',now);

FillChar(sBind,sizeof(sBind),0);

FillChar(sHead,sizeof(sHead),0);

str_i:=sizeof(sHead)+sizeof(sBind);

sBind.LonginType:=1;

strpcopy(sBind.LonginPass,FV_LoginPass);

strpcopy(sBind.LonginName,FV_LoginName);

abc:=htonl(FV_SNumber);

sHead.MessageLength:=htonl(str_i);

sHead.CommandId:=htonl(SGIP_Bind);

sHead.SNumber1:=abc;

sHead.SNumber2:=htonl(StrToInt(FV_Date1_S));

sHead.SNumber3:=htonl(StrToInt(FV_Date2_S));

stream1.WriteBuffer(sHead,sizeof(sHead));

stream1.WriteBuffer(sBind,sizeof(sBind));

memo1.Lines.Add('sHead.MessageLength '+inttostr(ntohl(sHead.MessageLength)));

memo1.Lines.Add('sHead.CommandId '+inttostr(ntohl(sHead.CommandId)));

bc:=ntohl(abc);

memo1.Lines.Add('sHead.SNumber1 '+inttostr(bc));

memo1.Lines.Add('sHead.SNumber2 '+inttostr(ntohl(sHead.SNumber2)));

memo1.Lines.Add('sHead.SNumber3 '+inttostr(ntohl(sHead.SNumber3)));

memo1.Lines.Add('sBind.LonginType '+inttostr(sBind.LonginType));

memo1.Lines.Add('sBind.LonginName '+sBind.LonginName);

memo1.Lines.Add('sBind.LonginPass '+sBind.LonginPass);

memo1.Lines.Add('------------------Bind请求已发送----------------------');

if stream1.WaitForData(5000) then

begin

fillchar(cHead,sizeof(cHead),0);

fillchar(cbind_resp,sizeof(cBind_Resp),0);

stream1.ReadBuffer(cHead,sizeof(cHead));

stream1.ReadBuffer(cBind_resp,sizeof(cBind_resp));

end;

memo1.Lines.Add('cHead.MessageLength '+inttostr(ntohl(cHead.MessageLength)));

bc:=ntohl(cHead.CommandId);

memo1.Lines.Add('cHead.CommandId '+inttostr(bc));

bc:=ntohl(cHead.SNumber1);

memo1.Lines.Add('cHead.SNumber1 '+inttostr(bc));

memo1.Lines.Add('cHead.SNumber2 '+inttostr(ntohl(cHead.SNumber2)));

memo1.Lines.Add('cHead.SNumber3 '+inttostr(ntohl(cHead.SNumber3)));

memo1.Lines.Add('cBind.LonginType '+inttostr(cBind_resp.Result));

stream1.Free;

end;

procedure TForm1.Button4Click(Sender: TObject);

file://type

{abc=packed record

head:SGIPHead;

submit:xSubmit;

end;}

var

FV_Date1_S,FV_Date2_S:string;

i,SendSize:integer;

file://xxx:abc;

stream2:twinsocketstream;

abc,bc:longword;

line1,line2:longword;

begin

stream2:=twinsocketstream.Create(clientsocket1.Socket,5000);

SendSize:=0;

memo1.Lines.Add('-------------------------submit--------------------------');

if not ClientSocket1.Active then

begin

memo1.Lines.Add('-------------------客户端没有打开,submit失败-------------');

exit;

end;

DateTimeToString(FV_Date1_S,'mmddhhnnss',now);

DateTimeToString(FV_Date2_S,'zzz',now);

FillChar(sSubmit,sizeof(sSubmit),0);

FillChar(sHead,sizeof(sHead),0);

with ssubmit do

begin

strpcopy(SPNumber,'4488');//;

ChargeNumber :='8613188890924';

UserCount :=1; file://1-100

{for i:=1 to UserCount do

begin

file://strpcopy(UserNumber[i-1].TelN,'8613065073355');//+T_Tel);// :array of TelCount; file://长度为UserCount

UserNumber[i-1].TelN:='8613011725853';

end;}

UserNumber:='8613188890924';

CorpID:='41027';//CorpID:='4488';//strpcopy(CorpID,FV_corpID);

ServiceType:='4488';//FV_SPNumber);//'4488';

FeeType :=1;

FeeValue :='0';

GivenValue :='0';

AgentFlag :=0;

MOrelatetoMTFlag :=2;

Priority :=0;

ExpireTime :='';

ScheduleTime :='';

ReportFlag :=1;

TP_pid :=0;

tp_udhi :=0;

MessageCoding :=15;

MessageType :=0;

MessageLength :=htonl(161);

strpcopy(MessageContent,T_msg); file://长度为 MessageLength;

file://Reserve :='';

end;

{line1:=sizeof(sHead);

line2:=sizeof(sSubmit);}

with sHead do

begin

abc:=htonl(FV_SNumber);

MessageLength:=htonl(sizeof(sHead)+sizeof(sSubmit)-3);

CommandId:=htonl(SGIP_Submit);

SNumber1:=abc;

SNumber2:=htonl(StrToInt(FV_Date1_S));

SNumber3:=htonl(StrToInt(FV_Date2_S));

end;

line1:=stream2.Write(shead,sizeof(shead));

line2:=stream2.Write(sSubmit,sizeof(sSubmit)-3);

if stream2.WaitForData(5000) then

begin

fillchar(cHead,sizeof(cHead),0);

fillchar(cSubmit_Resp,sizeof(cSubmit_Resp),0);

memo1.Lines.Add('read submit Head ..............');

try

stream2.ReadBuffer(cHead,sizeof(cHead));

stream2.ReadBuffer(cSubmit_Resp,sizeof(cSubmit_Resp));

except

on e:exception do

memo1.Lines.Add(e.Message);

end;

memo1.Lines.Add('read submit csubmit_resp ..............');

file://stream2.ReadBuffer(cBind_Resp,sizeof(cBind_resp));

end;

stream2.Free;

end;

procedure TForm1.ClientSocket1Read(Sender: TObject;

Socket: TCustomWinSocket);

var

commandI,PackSize:Longword;

Recv1I,Recv2I:integer;

begin

FillChar(sHead,sizeof(sHead),0);

FillChar(sBind,sizeof(sBind),0);

Recv1I:=socket.ReceiveBuf(sHead,sizeof(sHead));

commandI:=ntohl(sHead.CommandId);

PackSize:=ntohl(sHead.MessageLength);

if commandI=SGIP_UNBIND_RESP then

begin

memo1.Lines.Add('------------------接收到SGIP_UNBIND_RESP请求------------------');

exit;

end;

Recv2I:=socket.ReceiveBuf(sBind,sizeof(sBind));

if commandI=SGIP_BIND_RESP then

memo1.Lines.Add('---------------------SGIP_BIND_RESP------------------')

else

if commandI=SGIP_SUBMIT_RESP then

memo1.Lines.Add('---------------------SGIP_SUBMIT_RESP----------------')

else

memo1.Lines.Add('---------------------'+inttostr(commandI)+'------------------');

memo1.Lines.Add('MessageLength '+inttostr(ntohl(sHead.MessageLength)));

memo1.Lines.Add('CommandId '+inttostr(commandI));

memo1.Lines.Add('SNumber '+inttostr(ntohl(sHead.SNumber1))+' '+

inttostr(ntohl(sHead.SNumber2))+' '+inttostr(ntohl(sHead.SNumber3)));

memo1.Lines.Add('Result '+inttostr(sBind_Resp.Result));

memo1.Lines.add('------------------end SGIP_UNBIND_RESP-------------------');

end;

procedure TForm1.Button7Click(Sender: TObject);

var

FV_Date1_S,FV_Date2_S:string;

stream3:TWinSocketStream;

begin

Stream3:=TWinSocketStream.Create(clientSocket1.Socket,5000);

memo1.Lines.Add('-------------------向服务端发送UnBIND请求--------------------');

if not ClientSocket1.Active then

begin

memo1.Lines.Add('客户端没有打开');

stream3.free;

exit;

end;

DateTimeToString(FV_Date1_S,'mmddhhnnss',now);

DateTimeToString(FV_Date2_S,'zzz',now);

FillChar(sHead,sizeof(sHead),0);

sHead.MessageLength:=htonl(sizeof(sHead));

sHead.CommandId:=htonl(SGIP_UNBIND);

sHead.SNumber1:=htonl(FV_SNumber);

sHead.SNumber2:=htonl(StrToInt(FV_Date1_S));

sHead.SNumber3:=htonl(StrToInt(FV_Date2_S));

stream3.Write(sHead,20);

FillChar(sHead,20,0);

if stream3.WaitForData(5000) then

begin

stream3.ReadBuffer(sHead,20);

end;

stream3.Free;

end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;

Socket: TCustomWinSocket);

var

RecvSize1,RecvSize2,DeSize:integer;

commandI,MessageSize:LongWord;

begin

RecvSize1:=0;

RecvSize2:=0;

FillChar(cHead,SizeOf(cHead),0);

RecvSize1:=socket.ReceiveBuf(cHead,SizeOf(cHead));

commandI:=ntohl(cHead.CommandId);

MessageSize:=ntohl(cHead.MessageLength);

if commandI=SGIP_BIND then

begin

memo1.Lines.Add('*********************接收到Bind请求*********************');

FillChar(cBind,SizeOf(cBind),0);

FillChar(cBind_Resp,SizeOf(cBind_Resp),0);

RecvSize2:=Socket.ReceiveBuf(cBind,MessageSize-RecvSize1);

if (RecvSize2+RecvSize1)<>MessageSize then

begin

memo1.Lines.Add('**********************bind数据接收错误*******************');

exit;

end;

RecvSize2:=0;RecvSize1:=0;

cHead.CommandId:=htonl(SGIP_BIND_RESP);

cHead.MessageLength:=htonl(sizeof(cHead)+sizeof(cBind_Resp));

cBind_Resp.Result:=0;

RecvSize1:=Socket.SendBuf(cHead,SizeOf(cHead));

RecvSize2:=Socket.SendBuf(cBind_Resp,SizeOf(cBind_Resp));

if (RecvSize1+RecvSize2)<>ntohl(cHead.MessageLength) then

begin

memo1.Lines.Add('**********************响应bind请求错误***********************');

exit;

end;

end

else

if commandI=SGIP_DELIVER then

begin

memo1.Lines.Add('********************接收到SGIP_DELIVER请求********************');

DeSize:=SizeOf(cDeliver);

FillChar(cDeliver,SizeOf(cDeliver),0);

FillChar(cDeliver_Resp,SizeOf(cDeliver_Resp),0);

RecvSize2:=Socket.ReceiveBuf(cDeliver,MessageSize-RecvSize1);

if (RecvSize2+RecvSize1)<>MessageSize then

begin

memo1.Lines.Add('**********************SGIP_DELIVER数据接收错误*******************');

exit;

end;

RecvSize2:=0;RecvSize1:=0;

cHead.CommandId:=htonl(SGIP_DELIVER_RESP);

cHead.MessageLength:=htonl(sizeof(cHead)+sizeof(cDeliver_Resp));

cDeliver_Resp.Result:=0;

RecvSize1:=Socket.SendBuf(cHead,SizeOf(cHead));

RecvSize2:=Socket.SendBuf(cDeliver_Resp,SizeOf(cDeliver_Resp));

if (RecvSize1+RecvSize2)<>ntohl(cHead.MessageLength) then

begin

memo1.Lines.Add('**********************响应SGIP_DELIVER请求错误***********************');

exit;

end;

end

else

if commandI=SGIP_UNBIND then

begin

cHead.CommandId:=htonl(SGIP_UNBIND_RESP);

cHead.MessageLength:=htonl(sizeof(cHead));

memo1.Lines.Add('响应SGIP_UNBIND***************************');

RecvSize2:=Socket.SendBuf(cHead,sizeOf(cHead));

if RecvSize2<>ntohl(cHead.MessageLength) then

begin

memo1.Lines.Add('**********************SGIP_UNBIND发送错误*****************');

exit;

end;

end

else

begin

end;

end;

end.

//..............................................................

file://协

unit xy;

interface

uses

SysUtils;

const

SGIP_BIND =$1; file://对客户端验证

SGIP_BIND_RESP =$80000001; file://服务端返回验证请求

SGIP_UNBIND =$2; file://断开连接

SGIP_UNBIND_RESP =$80000002; file://返回断开连接状态

SGIP_SUBMIT =$3; file://向SMG提交MT短消息

SGIP_SUBMIT_RESP =$80000003; file://返回SP提交MT短消息状态

SGIP_DELIVER =$4; file://SMG向SP发送一条MO短消息

SGIP_DELIVER_RESP =$80000004; file://返回SMG状态

SGIP_REPORT =$5; file://向SP发送一条先前的submit命令的当前状态

SGIP_REPORT_RESP =$80000005; file://响应SMG状态

file://以下协议对SP无用

SGIP_ADDSP =$6; //

SGIP_ADDSP_RESP =$80000006; //

SGIP_MODIFYSP =$7; //

SGIP_MODIFYSP_RESP =$80000007; //

SGIP_DELETESP =$8; //

SGIP_DELETESP_RESP =$80000008; //

SGIP_QUERYROUTE =$9; //

SGIP_QUERYROUTE_RESP =$80000009; //

SGIP_ADDTELESEG =$a; //

SGIP_ADDTELESEG_RESP =$8000000a; //

SGIP_MODIFYTELESEG =$b; //

SGIP_MODIFYTELESEG_RESP =$8000000b; //

SGIP_DELETETELESEG =$c; //

SGIP_DELETETELESEG_RESP =$8000000c; //

SGIP_ADDSMG =$d; //

SGIP_ADDSMG_RESP =$8000000d; //

SGIP_MODIFYSMG =$e; //

SGIP_MODIFYSMG_RESP =$0000000e; //

SGIP_DELETESMG =$f; //

SGIP_DELETESMG_RESP =$8000000f; //

SGIP_CHECKUSER =$10; //

SGIP_CHECKUSER_RESP =$80000010; //

SGIP_USERRPT =$11; //

SGIP_USERRPT_RESP =$80000011; //

SGIP_TRACE =$1000; //

SGIP_TRACE_RESP =$80001000; //

type

TEMPTY=Record file://空纪录

end;

file://消息头

SGIPHead=Record

MessageLength :longword; file://消息的总长度(字节)

CommandId :longword; file://命令ID

SNumber1,SNumber2,SNumber3:longword; file://序列号

end;

file://消息体

XBind=Record //

LonginType :byte;

LonginPass :array[0..15] of char;

LonginName :array[0..15] of char;

Reserve :array[0..7] of char;

end;

Bind_Resp=Record

Result :byte;

Reserve :array[0..7] of char;

end;

//

Unbind=TEMPTY;

Unbind_Resp=TEMPTY;

//

TelCount=record file://手机号码

TelN :array[0..20] of char;

end;

XSubmit=Record

SPNumber :array[0..20] of char;

ChargeNumber :array[0..20] of char;

UserCount :byte; file://1-100

UserNumber :array[0..20] of char;//TelCount; file://长度为UserCount

CorpID :array[0..4] of char;

ServiceType :array[0..9] of char;

FeeType :byte;

FeeValue :array[0..5] of char;

GivenValue :array[0..5] of char;

AgentFlag :byte;

MOrelatetoMTFlag :byte;

Priority :byte;

ExpireTime :array[0..15] of char;

ScheduleTime :array[0..15] of char;

ReportFlag :byte;

TP_pid :byte;

TP_udhi :byte;

MessageCoding :byte;

MessageType :byte;

MessageLength :longword;

MessageContent :array[0..160] of char; file://长度为 MessageLength;

Reserve :array[0..7] of char;

end;

Submit_Resp=Record

Result :byte;

Reserve :array[0..7] of char;

end;

//

XDeliver=Record

UserNumber :array[0..20] of char;

SPNumber :array[0..27] of char;

{TP_pid :byte;

TP_udhi :byte;

MessageCoding :byte;

MessageLength :longword;}

MessageContent :array[0..254] of char; file://长度为 MessageLength;

Reserver :array[0..7] of char;

end;

Deliver_Resp=Record

Result :byte;

Reserve :array[0..7] of char;

end;

//

XReport=Record

SubSequNumber1,SubSequNumber2,SubSequNumber3 :longword;

ReportType :byte;

UserNumber :array[0..20] of char;

State :byte;

ErrorCode :byte;

Reserve :array[0..7] of char;

end;

Report_Resp=Record

Result :byte;

Reserve :array[0..7] of char;

end;

implementation

end.

file://、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、//

服务端

unit main;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, xy, ScktComp, StdCtrls,winsock;

type

TForm1 = class(TForm)

Memo1: TMemo;

ServerSocket1: TServerSocket;

procedure ServerSocket1ClientRead(Sender: TObject;

Socket: TCustomWinSocket);

procedure ServerSocket1ClientError(Sender: TObject;

Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;

var ErrorCode: Integer);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;

Socket: TCustomWinSocket);

type

SendPack = packed record

head: SGIPHead;

resp: Bind_Resp;

end;

var

ReHead:SGIPHead;

sresp:Bind_Resp;

ReBind:xBind;

ReDeliver:XDeliver;

ReReport:XReport;

i1,i2:integer;

str:string;

S_Number1,S_Number2,S_Number3,longI1:longword;

s_Pack:SendPack;

begin

fillchar(sresp,sizeof(sresp),0);

fillchar(ReHead,sizeof(ReHead),0);

i1:=Socket.ReceiveBuf(ReHead,sizeof(ReHead));

if i1<>sizeof(ReHead) then

begin

memo1.Lines.Add('Recv message Error exit');

exit;

end;

S_Number1:=ReHead.SNumber1;

S_Number2:=ReHead.SNumber2;

S_Number3:=ReHead.SNumber3;

ReHead.MessageLength:=ntohl(ReHead.MessageLength);

ReHead.CommandId:=ntohl(ReHead.CommandId);

ReHead.SNumber1:=ntohl(ReHead.SNumber1);

ReHead.SNumber2:=ntohl(ReHead.SNumber2);

ReHead.SNumber3:=ntohl(ReHead.SNumber3);

memo1.Lines.Add('read SMG message');

memo1.Lines.Add(inttostr(ReHead.MessageLength));

memo1.Lines.Add(inttostr(ReHead.CommandId));

memo1.Lines.Add(inttostr(ReHead.SNumber1));

memo1.Lines.Add(inttostr(ReHead.SNumber2));

memo1.Lines.Add(inttostr(ReHead.SNumber3));

if ReHead.CommandId=SGIP_UNBIND then

begin file://断开连接

FillChar(ReHead,SizeOf(ReHead),0);

ReHead.MessageLength:=htonl(SizeOf(ReHead));

ReHead.CommandId:=htonl(SGIP_UNBIND_RESP);

ReHead.SNumber1:=S_Number1;

ReHead.SNumber2:=S_Number2;

ReHead.SNumber3:=S_Number3;

i1:=socket.SendBuf(ReHead,sizeof(ReHead));

if i1<>sizeof(ReHead) then

memo1.Lines.Add('Send SGIP_UNBIND_Resp Error')

else

memo1.Lines.Add('Send SGIP_UNBIND_Resp OK');

end

else if ReHead.CommandId=SGIP_BIND then

begin file://SMG向SP发送一条MO短消息

FillChar(s_Pack,SizeOf(s_Pack),0);

FillChar(ReBind,SizeOf(ReBind),0);

socket.ReceiveBuf(ReBind,SizeOf(ReBind));

s_Pack.head.MessageLength:=htonl(SizeOf(s_Pack));

s_Pack.head.CommandId:=htonl(SGIP_BIND_RESP);

s_Pack.head.SNumber1:=S_Number1;

s_Pack.head.SNumber2:=S_Number2;

s_Pack.head.SNumber3:=S_Number3;

s_Pack.resp.Result:=0;

i1:=socket.SendBuf(s_Pack,SizeOf(s_Pack));

if i1<>SizeOf(s_Pack) then

memo1.Lines.Add('send SGIP_Bind_Resp Error')

else

memo1.Lines.Add('Send SGIP_bind_Resp');

end

else if ReHead.CommandId=SGIP_DELIVER then

begin

FillChar(s_Pack,SizeOf(s_Pack),0);

FillChar(ReDeliver,SizeOf(ReDeliver),0);

Socket.ReceiveBuf(ReDeliver,SizeOf(ReDeliver));

s_Pack.head.MessageLength:=htonl(SizeOf(s_Pack));

s_Pack.head.CommandId:=htonl(SGIP_DELIVER_RESP);

s_Pack.head.SNumber1:=S_Number1;

s_Pack.head.SNumber2:=S_Number2;

s_Pack.head.SNumber3:=S_Number3;

s_Pack.resp.Result:=0;

if socket.SendBuf(s_Pack,SizeOf(s_Pack)) <>SizeOf(s_Pack) then

memo1.Lines.Add('send SGIP_DELIVER_RESP Error')

else

memo1.Lines.Add('Send SGIP_DELIVER_RESP OK');

memo1.Lines.Add(ReDeliver.UserNumber);

memo1.Lines.Add(ReDeliver.SPNumber);

file://longI1:=ntohl(ReDeliver.MessageLength);

file://memo1.Lines.Add(inttostr(longI1)+' '+inttostr(ReDeliver.MessageLength));

memo1.Lines.Add(ReDeliver.MessageContent);

end

else if ReHead.CommandId=SGIP_REPORT then

begin

FillChar(s_Pack,SizeOf(s_Pack),0);

FillChar(ReReport,SizeOf(ReReport),0);

Socket.ReceiveBuf(ReReport,SizeOf(ReReport));

s_Pack.head.MessageLength:=htonl(SizeOf(s_Pack));

s_Pack.head.CommandId:=htonl(SGIP_REPORT_RESP);

s_Pack.head.SNumber1:=S_Number1;

s_Pack.head.SNumber2:=S_Number2;

s_Pack.head.SNumber3:=S_Number3;

s_Pack.resp.Result:=0;

if socket.SendBuf(s_Pack,SizeOf(s_Pack)) <>SizeOf(s_Pack) then

memo1.Lines.Add('send SGIP_Bind_Resp Error')

else

memo1.Lines.Add('Send SGIP_bind_Resp');

memo1.Lines.Add(ReReport.UserNumber);

memo1.Lines.Add(inttostr(ReReport.State));

end;

end;

procedure TForm1.ServerSocket1ClientError(Sender: TObject;

Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;

var ErrorCode: Integer);

var

errorMsg:string;

begin

case ErrorEvent of

eeGeneral: errorMsg:='eeGeneral';

eeSend: errorMsg:='eeSend';

eeReceive: errorMsg:='eeReceive';

eeConnect: errorMsg:='eeConnect';

eeDisconnect: errorMsg:='eeDisconnect';

eeAccept: errorMsg:='eeAccept';

end;

ErrorCode:=0;

Memo1.Lines.Add('Socket Error:'+errorMsg);

end;

end.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有