短信猫 TIdTCPServer TIdTCPClient
短信猫 服务端:
IdTCPServer1: TIdTCPServer;
IdAntiFreeze1: TIdAntiFreeze;
unit UnitSever; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdAntiFreezeBase,
IdAntiFreeze, StdCtrls, ExtCtrls, Sockets, IdUDPBase, IdUDPServer,UGBBig5Convert,Comobj, WordXP,
DB, DBTables, Buttons,OleServer,ExcelXP,ADODB, IdCustomTCPServer; type
TRevData=record
Data:string;
Flag:Boolean;
end; TDataThread=class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create(data:string);
end; TSeverFrm = class(TForm)
IdTCPServer1: TIdTCPServer;
IdAntiFreeze1: TIdAntiFreeze;
ButtonStart: TButton;
ButtonClose: TButton;
Memo1: TMemo;
Panel1: TPanel;
GroupBox2: TGroupBox;
Label1: TLabel;
Edit_COM: TEdit;
Label2: TLabel;
Edit_Tel: TEdit;
Label3: TLabel;
Button_Send: TButton;
Button1: TButton;
label_conn: TLabel;
memo_sms_txt: TMemo;
label_sms_stact: TLabel;
ListBox1: TListBox;
Button2: TButton;
procedure ButtonStartClick(Sender: TObject);
procedure ButtonCloseClick(Sender: TObject);
procedure IdTCPServer1Connect(AThread: TIdPeerThread);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure IdTCPServer1Disconnect(AThread: TIdPeerThread);
procedure Button1Click(Sender: TObject);
procedure Button_SendClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
//procedure Button2Click(Sender: TObject);
// procedure SpeedButton1Click(Sender: TObject);
// procedure ListBox1Click(Sender: TObject);
// procedure ListBox2Click(Sender: TObject);
private
{ Private declarations }
procedure WhileGetMSGdo;
function ServerReadBuffer(AThread: TIdPeerThread):string;
procedure ServerWtiteBuffer(AThread: TIdPeerThread;strMSG:string);
public
{ Public declarations }
sRevData:string;
end; function Sms_Connection(CopyRight:pchar;Com_Port,Com_BaudRate:integer;var Mobile_Type,CopyRightToCOM:PChar):integer;stdcall;external 'sms.dll';
function Sms_Send(Sms_TelNum:string;Sms_Text:string):integer;stdcall;external 'sms.dll';
Function Sms_Receive(Sms_Type:string;var Sms_Text:PChar):integer;stdcall;external 'sms.dll';
function Sms_Delete(Sms_Index:string):integer;stdcall;external 'sms.dll';
function Sms_AutoFlag :integer;stdcall;external 'sms.dll';
function Sms_NewFlag :integer;stdcall;external 'sms.dll';
function Sms_Disconnection :integer;stdcall;external 'sms.dll'; var
SeverFrm: TSeverFrm; implementation {$R *.dfm} function AppPath: string;
begin
Result := ExtractFilePath(Application.ExeName);
end; procedure WriteLog(s,Path:string);
var
TXT: TextFile;
begin
// FileStr := 'ERROR: '+FormatDateTime('YYYY-MM-DD HH:MM:SS',Now)+' | '+s;
try
AssignFile(TXT,Path + 'log.txt');
if FileExists(Path + 'log.txt') then
Append(TXT)
else
Rewrite(TXT);
Writeln(TXT,s);
Flush(TXT);
finally
CloseFile(TXT);
end;
end; procedure TDataThread.Execute();
begin
repeat until terminated ;
end; constructor TDataThread.Create(data:string);
begin end; function TSeverFrm.ServerReadBuffer(AThread: TIdPeerThread):string;
var
ts:TStrings;
stream:TStream;
begin
try
stream := TStringStream.Create(''); //ノㄤ摸Stream钡Μぃ摸计沮
AThread.Connection.ReadStream(stream);
stream.Position :=;
ts.LoadFromStream(stream);
Result := ts.Text;
finally
stream.Free;
end;
end; procedure TSeverFrm.ServerWtiteBuffer(AThread: TIdPeerThread;strMSG:string);
var
ts:TStrings;
stream:TStream;
begin
try
stream := TStringStream.Create(strMSG);
AThread.Connection.WriteStream(stream);
finally
stream.Free;
end;
end; procedure TSeverFrm.ButtonStartClick(Sender: TObject);
begin
IdTCPServer1.Active := True;
ButtonStart.Enabled := False;
ButtonClose.Enabled := True;
Memo1.Lines.Add('MSG: Successful Server Startup...');
end; procedure TSeverFrm.ButtonCloseClick(Sender: TObject);
begin
IdTCPServer1.Active := False;
ButtonStart.Enabled := True;
ButtonClose.Enabled := False;
Memo1.Lines.Add('MSG: Server is Down...');
end; procedure TSeverFrm.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
try
Memo1.Lines.Add('MSG: Host'+AThread.Connection.Socket.Binding.PeerIP+'Connect Server OK');
AThread.Connection.WriteLn('Connect To Server Success...'); //临琌BufferH摆fuck
//ServerWtiteBuffer(AThread,'硈钡Θ');
finally end;
end; procedure TSeverFrm.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
if AThread=nil then Exit;
if not AThread.Connection.Connected then Exit;
if AThread.Terminated then Exit;
try
sRevData := AThread.Connection.ReadLn();
if Pos('SENDMSG',sRevData)> then
begin
memo1.Lines.Add(sRevData) ;
memo_sms_txt.Text:=sRevData;
AThread.Synchronize(WhileGetMSGdo);
AThread.Connection.WriteLn('Send Success');
end;
except
WriteLog('ERROR: '+DateTimeToStr(Now)+' | '+AThread.Connection.Socket.Binding.PeerIP+' Receive Data Eexception',AppPath);
end; end;
procedure TSeverFrm.WhileGetMSGdo; //め狠祇癳㏑ㄓ才兵ン秈︽矪瞶
begin
sRevData:=memo_sms_txt.Text;
Button_Send.Click;
{if Sms_Send(Trim(Edit_Tel.Text),memo_sms_txt.Text)=1 then
label_sms_stact.Caption := 'Send Success+'
else
label_sms_stact.Caption := 'Send Failed'; }
end; procedure TSeverFrm.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
AThread.Connection.WriteLn('Server Is Down...');
end; procedure TSeverFrm.Button1Click(Sender: TObject);
var
Mobile_Type:pchar;
CopyRight:pchar;
CopyRightToCOM:pchar;
begin
CopyRight:=PChar('//上海迅赛信息技术有限公司,网址www.xunsai.com//'); //硂琿絏璶叫ぃ璶э
if Sms_Connection(CopyRight,StrToInt(Edit_COM.text),,Mobile_Type,CopyRightToCOM)<> then
begin
Label_conn.Caption:='OK:'+Mobile_Type+'!';
end
else
Label_conn.Caption:='NOT OK!'
end; procedure TSeverFrm.Button_SendClick(Sender: TObject);
var
i:Integer;
begin
{if Sms_Send(Trim(Edit_Tel.Text),memo_sms_txt.Text)=1 then
label_sms_stact.Caption := 'Send Success+'
else
label_sms_stact.Caption := 'Send Failed'; }
for i:= to ListBox1.Items.Count- do
begin
if Sms_Send(Trim(ListBox1.Items.Strings[i]),memo_sms_txt.Text)= then
label_sms_stact.Caption := 'Send Success+'
else
label_sms_stact.Caption := 'Send Failed';
end;
end;
//------------------------------------------------------------------------------
procedure TSeverFrm.Button2Click(Sender: TObject);
Var
Filename:String;
MyFile:Textfile;
i:Integer;
S:string;
begin
Filename:='D:/a.txt';
AssignFile(Myfile,filename);
try
reset(Myfile);
Except
rewrite(Myfile);
end;
i:=;
while not seekEof(Myfile) do
begin
readln(Myfile,s);
ListBox1.Items.Add(S);
inc(i);
end;
CloseFile(Myfile);
end; end.
服务端
客户端
IdTCPClient1: TIdTCPClient;
IdAntiFreeze1: TIdAntiFreeze;
IdIPWatch1: TIdIPWatch;
unit UnitClient; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, StdCtrls, ExtCtrls, IdIPWatch; type
TRevData=record
Data:string;
Flag:Boolean;
end; TClientFrm = class(TForm)
IdTCPClient1: TIdTCPClient; IdAntiFreeze1: TIdAntiFreeze;
Panel1: TPanel;
Edit_Host: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit_Port: TEdit;
Button_Connet: TButton;
Button_Close: TButton;
Memo1: TMemo;
Button_Send: TButton;
MemoSend: TMemo;
Label3: TLabel;
IdIPWatch1: TIdIPWatch;
procedure Button_ConnetClick(Sender: TObject);
procedure Button_SendClick(Sender: TObject);
procedure Button_CloseClick(Sender: TObject);
private
{ Private declarations }
SendData:string;//沮惠璶э跑祇癳摸ノ挡篶砰舱摸獺
function ClientReadBuffer(IDTCP: TIdTCPClient):string;
procedure ClientWtiteBuffer(IDTCP: TIdTCPClient;strMSG:string);
public
{ Public declarations }
end; var
ClientFrm: TClientFrm; implementation {$R *.dfm} function TClientFrm.ClientReadBuffer(IDTCP: TIdTCPClient):string;
var
ts:TStrings;
stream:TStream;
begin
try
stream := TStringStream.Create(''); //ノㄤ摸Stream钡Μぃ摸计沮
IDTCP.ReadStream(stream);
stream.Position :=;
ts.LoadFromStream(stream);
Result := ts.Text;
finally
stream.Free;
end;
end; procedure TClientFrm.ClientWtiteBuffer(IDTCP: TIdTCPClient;strMSG:string);
var
ts:TStrings;
stream:TStream;
begin
try
stream := TStringStream.Create(strMSG);
IDTCP.WriteStream(stream);
finally
stream.Free;
end;
end; procedure TClientFrm.Button_ConnetClick(Sender: TObject);
var
stream:TStringStream;
begin
IdTCPClient1.Host := Trim(Edit_Host.Text);
IdTCPClient1.Port := StrToInt(Edit_Port.Text);
Memo1.Lines.Add('タ硈钡狝叭竟' + Edit_Host.Text + '...');
with IdTCPClient1 do
begin
try
Connect();
try
Memo1.Lines.Add(ReadLn());
//Memo1.Lines.Add(ClientReadBuffer(IdTCPClient1)+'++');
//Memo1.Lines.LoadFromStream(stream);
Button_Connet.Enabled := False;
Button_Close.Enabled := True;
except
Memo1.Lines.Add('狝叭竟礚臫莱...');
IdTCPClient1.Disconnect();
end;
except
Memo1.Lines.Add('礚猭ミ' + Edit_Host.Text + '硈钡...');
end;
end;
Button_Send.Enabled := True;
end; procedure TClientFrm.Button_SendClick(Sender: TObject);
begin
try
SendData := MemoSend.Text;
IdTCPClient1.WriteLn(SendData+'--Come From'+IdIPWatch1.LocalIP);
Memo1.Lines.Add(IdTCPClient1.ReadLn());
except
IdTCPClient1.Disconnect();
Button_Connet.Enabled := True;
end;
end;
procedure TClientFrm.Button_CloseClick(Sender: TObject);
var
strip:string;
begin
try
strip := IdIPWatch1.LocalIP; //IdTCPClient1.Socket.LocalName;;
IdTCPClient1.WriteLn('SENDMSG诀'+strip+' 笆耞秨硈钡');
//Memo1.Lines.Add(IdTCPClient1.ReadLn()) ;
IdTCPClient1.Disconnect;
Memo1.Lines.Add('狝叭竟硈钡耞秨');
Button_Connet.Enabled := True;
//Button_Send.Enabled := False; except
end;
end; end.
客户端
读取txt
procedure TSeverFrm.Button2Click(Sender: TObject);
Var
Filename:String;
MyFile:Textfile;
i:Integer;
S:string;
begin
Filename:='D:/a.txt';
AssignFile(Myfile,filename);
try
reset(Myfile);
Except
rewrite(Myfile);
end;
i:=0;
while not seekEof(Myfile) do
begin
readln(Myfile,s);
ListBox1.Items.Add(S);
inc(i);
end;
CloseFile(Myfile);
end;
短信猫 TIdTCPServer TIdTCPClient的更多相关文章
- 在网页程序或Java程序中调用接口实现短信猫收发短信的解决方案
方案特点: 在网页程序或Java程序中调用接口实现短信猫收发短信的解决方案,简化软件开发流程,减少各应用系统相同模块的重复开发工作,提高系统稳定性和可靠性. 基于HTTP协议的开发接口 使用特点在网页 ...
- 基于Socket客户端局域网或广域网内共享同一短信猫收发短信的开发解决方案
可使同一网络(局域网或广域网)内众多客户端,共享一个短信猫设备短信服务器进行短信收发,短信服务器具备对客户端的管理功能. 下面是某市建设银行采用本短信二次开发平台时实施的系统方案图: 在该方案中,考虑 ...
- C# 短信猫(SMS cat) 操作源码开发经验
我曾经开发的某项目需要使用短信猫模块,要求使用C#编程操作.能独立使用的动态链接库之一就是网上流传的sms.dll,但它的功能较少,不能满足需求,鉴于一时找不到合适的完整代码,我深入研究了短信协议,借 ...
- Java应用短信猫
首先确定短信猫正常连接到主机,并安装SIM卡.先用超级终端测试短息猫能不能用.安装minicom:#sudo apt-get install minicom安装完成后,执行#sudo minicom ...
- wavecom短信猫常用AT命令
wavecom短信猫常用AT命令 一.一般命令 1. AT+CGMI 给出模块厂商的标识. 2. AT+CGMM 获得模块标识.这个命令用来得到支持的频带 (GSM 900,DCS 1800 或PCS ...
- CDMA电信短信猫支持189等电信号码可二次开发
CDMA电信短信猫支持189等电信号码可二次开发 这款短信猫采用法国wavecom Q2358C模块,支持短信猫二次开发,可提供短信猫二次开发包下载测试.提供相关资料文档. 此款CDMA电信短信猫有串 ...
- VB短信猫开发包,支持超长短信
一.短信猫开发包(长短信/异步调用)说明: 短信猫开发包以OCX控件的形式提供,支持Windows平台下常用的开发工具:如VB.VB.net.VC++.Power Builder.C#.DELPH ...
- centos6.5 短信猫部署发短信
本文为在centos下部署短信猫发短信使用,以下为具体环境和步骤说明,欢迎留言! 一.环境说明 服务器:centos6.5 x64 依赖包:lockdev-1.0.1-18.el6.x86_64.rp ...
- Linux系统中调用短信猫发送短信(笔记)
1, 拷贝底层串口依赖的librxtxSerial.so到JDK安装路径cp librxtxSerial.so /usr/java/{0}/jre/lib/{1} # {0}: JDK的基础目录,例如 ...
随机推荐
- jsonp注意事项
自己测试的: <?php '); } }); } </script> <!DOCTYPE htm ...
- July 5th, Week 28th Tuesday, 2016
If you smile when no one else is around, you really mean it. 独处的时候你的笑容才是发自内心的笑容. Human beings are so ...
- function与感叹号
原文链接:https://swordair.com/function-and-exclamation-mark/ 最近有空可以让我静下心来看看各种代码,function与感叹号的频繁出现,让我回想起2 ...
- c语言字符集
一.字符常量 'A', 'B','\n','\'','1' 二.字符类型变量的赋值 char c1='A'; char c2='b'; char c3=65; c2='\''; c2='\n'; 三. ...
- find 查找文件 -exec 然后压缩 查看tar包的内容
[root@cs Downloads]# find ./ -name "banner*" -exec tar -cvf k.tar "{}" \; ./bann ...
- DOM – 7.动态创建DOM + 8.innerText innerHTML value
7.动态创建DOM 8.innerText innerHTML value 7+8 练习:案例:点击按钮动态增加网站列表,分两列,第一列为网站的名字,第二列为带网站超链接的网站名.增加三行常见网站 ...
- C#值类型与引用类型
值类型(Value Type),值类型实例通常分配在线程的堆栈(stack)上,并且不包含任何指向实例数据的指针,因为变量本身就包含了其实例数据.其在MSDN的定义为值类型直接包含它们的数据,值类型的 ...
- ***LINUX添加PHP环境变量:CentOS下将php和mysql命令加入到环境变量中
CentOS系统下如何将PHP和mysql命令加入到环境变量中,在Linux CentOS系统上 安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到 ...
- Ubuntu / Win7 安装db2 v10.5
抓紧下载v10.5fp1_linuxx64_expc.tar.gz到~/Downloads/java_softcd java_softtar xf v10.5fp1_linuxx64_expc.tar ...
- css 全局 兼容性问题
css 笔记 第一种:常用的全局CSS属性设置 //参考大型网站,如凤凰网 (1)清除所有的标记的内外边距 body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,p ...