SGIP的delphi原码
在网上找了好长时间,也没有发现有SGIP的例子,伤感之余,终于做了一个Delphi6.0的SGIP例子
包含了一个服务端和一个客户端,协议共用,服务端为非阻塞长连接,客户端为阻塞短连接,
程序写的很乱,风格也很差,希望高手多多指教
(dulcet99@163.com,dulcet99@sina.com)file://客户端
unit TestMain;inte易做图ce
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.SN
补充:软件开发 , Delphi ,