After searching for a long time on the Internet, I couldn't find any SGip example. I was sad and finally made a SGIP example for Delphi6.0.
Contains a server and a client, the protocol is shared, the server is a non-blocking long connection, and the client is a blocking short connection.
The program is very messy and the style is very poor. I hope experts can give me some advice.
([email protected],[email protected])
file://client
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='I wrote your name in the sky and it was not taken away by the wind';
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://client protocol definition
sHead: SGIHead; file://Message header definition
sBind: XBind; file://Connection request verification
sBind_Resp: Bind_Resp; file://Response to connection request verification
sSubmit: XSubmit; file://SP->SMG submit SMS
sSubmit_Resp: Submit_Resp; file://SMG responds to the SMS status submitted by SP
sDeliver: XDeliver; file://SMG->SP submit SMS
sDeliver_Resp: Deliver_Resp; file://SP responds to the SMS status submitted by SMG
sReport: XReport; file://SMG->SP previous SMS status
sReport_Resp: Report_Resp; file://Response command execution status
file://server protocol definition
cHead: SGIHead; file://Message header definition
cBind: XBind; file://Connection request verification
cBind_Resp: Bind_Resp; file://Response to connection request verification
cSubmit: XSubmit; file://SP->SMG submit SMS
cSubmit_Resp: Submit_Resp; file://SMG responds to the SMS status submitted by the SP
cDeliver: XDeliver; file://SMG->SP submit SMS
cDeliver_Resp: Deliver_Resp; file://SP responds to the SMS status submitted by SMG
cReport: XReport; file://SMG->SP previous SMS status
cReport_Resp: Report_Resp; file://Response command execution status
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket1.Active:=false;
if ClientSocket1.Active then
memo1.Lines.Add('Client shutdown failed')
else
memo1.Lines.Add('Client closed successfully');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Active:=true;
if ClientSocket1.Active then
memo1.Lines.Add('Client opened successfully')
else
memo1.Lines.Add('Client opening failed');
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
ServerSocket1.Active:=true;
if ServerSocket1.Active then
memo1.Lines.Add('Server opened successfully')
else
memo1.Lines.Add('Server opening failed');
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
ServerSocket1.Active:=false;
if ServerSocket1.Active then
memo1.Lines.Add('Server shutdown failed')
else
memo1.Lines.Add('Server closed successfully');
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('-------------------Send BIND request to the server------------------ --');
if not ClientSocket1.Active then
begin
memo1.Lines.Add('The client is not open');
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 request has been sent-------------------------- -');
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('------------------The client is not open, submit failed-------------');
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://length is 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://length is 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('------------------Received SGIP_UNBIND_RESP request------------------');
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('-------------------Send UnBIND request to the server------------------ --');
if not ClientSocket1.Active then
begin
memo1.Lines.Add('The client is not open');
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('************************Received Bind request****************** ***');
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 data receiving error********************** **');
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('************************Error in response to bind request********************** ******');
exit;
end;
end
else
if commandI=SGIP_DELIVER then
begin
memo1.Lines.Add('************************Received SGIP_DELIVER request************************ *');
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 data reception error********************** **');
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('************************Response to SGIP_DELIVER request error************************ ******');
exit;
end;
end
else
if commandI=SGIP_UNBIND then
begin
cHead.CommandId:=htonl(SGIP_UNBIND_RESP);
cHead.MessageLength:=htonl(sizeof(cHead));
memo1.Lines.Add('Response to SGIP_UNBIND******************************');
RecvSize2:=Socket.SendBuf(cHead,sizeOf(cHead));
if RecvSize2<>ntohl(cHead.MessageLength) then
begin
memo1.Lines.Add('**********************SGIP_UNBIND sending error************************' );
exit;
end;
end
else
begin
end;
end;
end.
//................................................................ ............
file://protocol
unit xy;
interface
uses
SysUtils;
const
SGIP_BIND =$1; file://Verify client
SGIP_BIND_RESP=$80000001; file://server returns verification request
SGIP_UNBIND =$2; file://disconnect
SGIP_UNBIND_RESP =$80000002; file://Return to disconnected status
SGIP_SUBMIT =$3; file://Submit MT short message to SMG
SGIP_SUBMIT_RESP =$80000003; file://Return SP submission MT short message status
SGIP_DELIVER =$4; file://SMG sends an MO short message to SP
SGIP_DELIVER_RESP =$80000004; file://return to SMG status
SGIP_REPORT =$5; file://Sends the current status of a previous submit command to the SP
SGIP_REPORT_RESP=$80000005; file://Response SMG status
file://The following protocols are useless for 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://empty record
end;
file://message header
SGIPHead=Record
MessageLength:longword; file://The total length of the message (bytes)
CommandId :longword; file://commandID
SNumber1,SNumber2,SNumber3:longword; file://serial number
end;
file://message body
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://mobile phone number
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://length is 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://length is 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://length is 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://,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,//
Server
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;
varErrorCode: 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: SGIHead;
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://disconnect
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 sends an MO short message to SP
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;
varErrorCode: 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.