SGIP的delphi原码

2008-04-10 02:57:49来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

在网上找了好长时间,也没有发现有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));

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:分布式数据库应用开发正解 [系列之一]

下一篇:Delphi 完全时尚手册之 CoolBar 篇---实现 CoolBar 的新特性 Che