It has been found for a long time on the Internet, nor did it find SGIP examples, and the sadness, finally made a Delphi6.0's SGIP example contains a server and a client, the protocol is shared, the server is non-blocking long connection The client is blocking short connection, the program is very chaotic, the style is also very poor, I hope the master will advise (Dulcet99 @ 163.com, dulcet99 @ sina.com)
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, did not be 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: T Object; Socket: TCustomWinSocket); private {Private declarations} public {Public declarations} file: // protocol defines client sHead: SGIPHead; file: // message header defines sBind: XBind; file: // connection request verification sBind_Resp: Bind_Resp File: // Response Connection Request Verification SSUBMIT: XSubmit; File: // SP-> SMG Submit SSUBMIT_RESP: SUBMIT_RESP; File: // SMG Response SP Submit SMS SMS SMS State SDELIVER: XDELIVER; File: // SMG-> SP SMS SDELIVER_RESP: DELIVER_RESP; File: // SP response SMG submitted SMS status SREPORT: XReport; file: // SMG-> SP previous SMS status SREPORT_RESP: Report_RESP;
File: // Response Command Performance File: // Service Protocol Definition CHEAD: SGPHEAD; File: // Message Definition CBIND: XBIND; File: // Connection Request Verification CBIND_RESP: BIND_RESP; File: // Response Connection Request Verification CSubmit: xsubmit; file: // sp-> SMG SMS csubmit_resp: submit_resp; file: // SMG Response SP submitted SMS status CDELIVER: XDELIVER; File: // SMG-> SP SMS CDELIVER_RESP: DELIVER_RESP; File: / / SP responds to SMG submitted SMS status 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.act: = false; if clientsocket1.active dam1.lines.add ('Close Close Failed ") Else Memo1.Lines.Add (' Client Close Success') ;
Procedure TForm1.Button1Click (Sender: Tobject); Begin ClientSocket1.Active: = true; ifclientsocket1.active dam1.lines.add ('client open success "Else Memo1.Lines.Add (' client open failed") ;
Procedure TForm1.Button6Click (Sender: Tobject); Begin Serversocket1.Active: = true; if serversocket1.active dam1.lines.add ('server open success') Else memo1.lines.add (' server open failed ") ;
Procedure TForm1.Button5Click (Sender: TOBJECT); Begin Serversocket1.Active: = false; if serversocket1.active dam1.lines.add ('server closing failed ") Else Memo1.Lines.Add (' server closing success") ;
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 requests to the server -------------------------------------------------------------------------------------------------------------- '); If not clientsocket1.active the beginning (' client is not open "; exit; end; datetimetostring (fv_date1_s, 'mmddhhnnsss', 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' INTSTOSTR (Ntohl (Shead.MessageLength))); Memo1.Lines.Add ('Shead.commandid' INTOSTR (NTOHL (SHEAD. Commandid))))))); BC: = NTOHL (ABC); Memo1.Lines.Add ('Shead. Snumber1' INTOSTR (BC)); Memo1.Lines.Add ('Shead.Snumber2' INTOSTR (NTOHL (Shead. Snumber2 )))); Memo1.Lines.Add ('Shead.Snumber3' INTOSTR (NtOHL (SHEAD.SNUMBER3)))); Memo1.Lines.Add ('sbind.longintype' INTOSTR (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' INTOSTR (BC)); bc: = ntohl (chead.snumber1); Memo1.Lines.Add ('Chead. SNUMBER1 ' INTOSTR (BC)); Memo1.Lines.Add (' Chead. Snumber2 ' INTOSTR (NTOHL (Chead.snumber2)))))); Memo1.Lines.Add (' Chead. Snumber3 ' INTOSTR (NTOHL (Chet. Snumber3))))))))))); Memo1.Lines.Add ('cbind.longintype' INTOSTR (CBIND_RESP.RESULT)); stream1.free;
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 dam Memo1.Lines.add ('------------------ The client is not open, Submit failed ---------- --- '); EXIT; END; DATETITOSTRING (fv_date1_s,' mmddhhnnsss', 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: = '861318890924'; usercount: = 1; file: // 1-100 {for i: = 1 To Usercount DO Begin file: // strpcopy (usernumber [i-1] .teln, '8613065073355'); // t_tel); //: array of telco Usercount usernumber [i-1] .TELN: = '8613011725853'; end;} usernumber: = '8613188890924'; Corpid: = '41027'; // Corpid: = '4488'; / / STRPCOPY (CORPID, FV_CORPID); ServiceType: = '4488'; // fv_spnumber); // '4488'; Feetype: = 1; FeEtype: = '0'; givenvalue: = '0'; agentflag: = 0; MoreLateTomtflag: = 2; priority: = 0; ExpiRetime: = '; scheduletime: ='; reportflag: = 1; TP_PID: = 0;
TP_UDHI: = 0; 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, sizeof (chead); stream2.readbuffer (csubmit_resp, sizeof (csubmit_resp) ); Except ON E: Exception Do Memo1.Lines.Add (E.MESSAGE); End; Memo1.Line S.Add ('read submit csubmit_resp ............'); file: //stream2.readbuffer (cbind_resp, sizeof (cbind_resp)); end; stream2.free;
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 ( ' ------------------ Receive SGIP_UNBIND_RESP Request ---------------- '); End; 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 (' ------------------- ' INTOSTR (Commandi) '------------------'); Memo1.Lines.Add ('MessageLength' INTOSTR (NTOHL (SHEAD.MESSAGELENGTH)); MEMO1. Lines.add ('CommandId' INTOSTR (Commandi)); Memo1.Lines.Add ('SNUM Ber ' INTOSTR (NTOHL (SHEAD.SNUMBER1)) ' ' INTOSTR (NTOHL (SHEAD.SNUMBER2)) ' ' INTOSTR (NTOHL (SHEAD.SNUMBER3))); Memo1.Lines.Add (' Result ' INTTOSTR (SBIND_RESP.RESULT)); Memo1.Lines.Add ('----------------- End SGIP_UNBIND_RESP --------------- ---- ');
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 requests to the server ------------------ '); if not clientsocket1.active dam Memo1. Lines.add ('client is not open "; stream3.free; exit; end; datetimetostring (fv_date1_s,' mmddhhnnsss', now); DateTimetString (fv_date2_s, 'zzz', new; 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); 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; b EGIN 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.MerationLength: = HTONL (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 ('******************** Response BIND request error ******************************* ** '); exit; end; end else if command I = 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 Receive 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 SGIP_DELIVER Request error ******** ****************); exit; end; end else if commandi = SGIP_UNBIND THEN BEGIN CHEAD.COMMANDID: = HTONL (SGIP_UNBIND_RESP); chead.MessageLength: = HTONL (CHEAD )); Memo1.Lines.Add ('responding to SGIP_UNBIND ******************************; recvsize2: = socket.sendbuf (Chead Sizeof (Chead); if recvsize2 <> ntohl (chead.MessageLength) Then Begin Memo1.Lines.Add ('********************* * SGIP_UNBIND Send Error ***************** '); exit; end; end; end; end; end. // .............. ............................................... File: // Protocol Unit XY;
InterfaceUses system; file: // Verify sgip_bind_resp = $ 8000000001; file: // server return verification request SGIP_UNBIND = $ 2; file: // Disconnect SGIP_UNBIND_RESP = $ 80000002; file: // Return broken Open-connected status SGIP_SUBMIT = $ 3; file: // Submit MT short message SGIP_SUBMIT_RESP = $ 8000000003; file: // Return to SP / DLIP_DELIVER = $ 4; file: // SMG Send a MO short message SGIP_DELIVER_RESP = $ 80000004; file: // Returns SMG status SGIP_REPORT = $ 5; file: // Send a previous SUBMIT command to the SGIP_REPORT_RESP = 80000005; file: // Response SMG status File: // The following protocols 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_ADD TELESEG_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: // Null Record End; File: // Message SGPHEAD = Record MessageLength: Longword; File: // Message Total length (bytes) CommandID: longword File: // Command ID SNUMBER1, SNUMBER2, SNUMBER3: Longword; File: // Serial number end; file: // Message 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 results: byte; reserve: array [0..7] of char; end; // unbind = Tempty; unbind_resp = Tempty; // 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; service: array [0..9] of char; feetype: Byte; FeETYPE: BYTE ;FEETYPE: Array [0..5] of char; givenvalue: array [0..5] Of circs; more; priority: Byte; ExpiRetime: array [0..15] of char; scheduletime: array [0..15] of char; reportflag: Byte; tp_pid: byte; tp_udhi: byte; tp_udhi: byte MessageCoding: Byte; MessageLength: longword; messagecontent: array [0..160] of char; file: // Length is MessageLength; Reserve: array [0..7] of char; end;
Submit_resp = record: 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; MESSAGELENGTED: 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; reserve: array [0..7] of char;
Implementation.
File: //, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
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}}}} 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; 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 (Intest (Rehead.MessageLength)); M EMO1.LINES.ADD (INTTOSTR (Rehead.Commandid)); Memo1.Lines.Add (INTTOSTR (REHEAD.SNUMBER1)); Memo1.Lines.Add (INTTOSTR (Rehead. Snumber2)); Memo1.Lines.Add (INTSTR 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.COMMAND = SGIP_BIND THEN BEGIN FILE: // SMG Send a MO short message to SP Fillchar (S_Pack, 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.snumb ER2: = 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 (retreport.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' Esend: ErrorMsg: = 'eesend'; EeReceive: ErrorMsg: = 'Eereceive'; EECONNECT: ErrorMsg: = 'EECONNECT'; EEDISCONNECT: ERRORMSG: = 'EEDISCONNECT'; EEACCEPT: ERRORMSG: = 'EE Accept '; End; ErrorCode: = 0; Memo1.Lines.Add (' Socket Error: ' ErrorMSG);
End.