Q
qshd
Unregistered / Unconfirmed
GUEST, unregistred user!
[]我用DELPHI写了一个收发短信(移动的CMPP协议)的小程序,可是总是无法和网关模拟器连接,谁能帮助我,将感激不尽!
谢谢!
谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls, jpeg, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
ClientSocket1: TClientSocket;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Edit3: TEdit;
Label3: TLabel;
Button3: TButton;
StatusBar1: TStatusBar;
Memo1: TMemo;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1Listen(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ThreadStart(Sender: TObject;
Thread: TServerClientThread);
procedure ServerSocket1ThreadEnd(Sender: TObject;
Thread: TServerClientThread);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure Button4Click(Sender: TObject);
procedure ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure ClientSocket1Write(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
type cmpp_connect=record
// total_length:Longword;
// command_id:Longword;
// sequence_id:Longword;
source_addr:array[0..5]of char;
authenticatorSP:array[0..31]of char;
version:byte;
timestamp:longword;
end;
var
Form1: TForm1;
MS: TMemoryStream;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if clientsocket1.active then
begin
clientsocket1.active:=false;
end;
clientsocket1.Port:=strtoint(edit2.text);
clientsocket1.address:=edit1.Text;
try
clientsocket1.Active:=true;
except
showmessage('连接出错!');
end
end;
procedure TForm1.Button2Click(Sender: TObject);
var cmpp_conn:cmpp_connect;
var str:string;
begin
//cmpp_conn.total_length:=35;
//cmpp_conn.command_id:=1;
//cmpp_conn.sequence_id:=1;
cmpp_conn.source_addr:='000168';
cmpp_conn.AuthenticatorSP :='758e018e918a49cc2ab0d245847a7105';
cmpp_conn.version:=1;
cmpp_conn.timestamp:=0428111700;
clientsocket1.Socket.SendBuf(cmpp_conn,sizeof(cmpp_conn));
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if clientsocket1.active then
begin
clientsocket1.Socket.Disconnect(1);
clientsocket1.active:=false;
end;
end;
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.SimpleText:='有信息返回!';
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.SimpleText:='连接被断开!';
end;
procedure TForm1.ServerSocket1Listen(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.SimpleText:='正在监听'+edit2.text;
end;
procedure TForm1.ServerSocket1ThreadStart(Sender: TObject;
Thread: TServerClientThread);
begin
statusbar1.SimpleText:='监听开始、、、、';
end;
procedure TForm1.ServerSocket1ThreadEnd(Sender: TObject;
Thread: TServerClientThread);
begin
statusbar1.SimpleText:='监听结束、、、';
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var cmpp_conn2:cmpp_connect;
var re_str:string;
begin
statusbar1.SimpleText:='有数据返回!';
socket.ReceiveBuf(cmpp_conn2,37);
re_str:=socket.ReceiveText;
memo1.Lines.Add('command_id:'+inttostr(cmpp_conn2.command_id));
memo1.Lines.Add('authenticatorsp:'+cmpp_conn2.authenticatorsp);
memo1.Lines.Add('source_addr:'+cmpp_conn2.source_addr);
memo1.Lines.Add('timestamp:'+inttostr(cmpp_conn2.timestamp));
memo1.Lines.Add('-------------------------------');
memo1.lines.add(re_str);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
memo1.Lines.Text:='';
end;
procedure TForm1.ClientSocket1Connecting(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.SimpleText:='SOCKET 连接成功!';
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.SimpleText:='SOCKET 连接被断开!';
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
statusbar1.SimpleText:='SOCKET 连接错误!';
end;
procedure TForm1.ClientSocket1Write(Sender: TObject;
Socket: TCustomWinSocket);
begin
statusbar1.SimpleText:='正在尝试发送数据!';
end;
end.