在網上找了好長時間,也沒有發現有SGIP的例子,傷感之余,終於做了一個Delphi6.0的SGIP例子
包含了一個服務端和一個客戶端,協議共用,服務端為非阻塞長連接,客戶端為阻塞短連接,
程序寫的很亂,風格也很差,希望高手多多指教
([email protected],[email protected])
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;