短信猫 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 :=0;
     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)>0 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),9600,Mobile_Type,CopyRightToCOM)<>0 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:=0 to ListBox1.Items.Count-1 do
  begin
    if Sms_Send(Trim(ListBox1.Items.Strings[i]),memo_sms_txt.Text)=1 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:=0;
  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 :=0;
     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(5000);
      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;

  

时间: 2024-10-07 05:06:42

短信猫 TIdTCPServer TIdTCPClient的相关文章

短信猫信息记录读取程序

有二年多时间没有写程序了写起程序太陌生了要求写一个短信猫信息记录的读取程序买了个短信猫下载了一个动态链接库sms.dll依据所给案例写了一个运行比较稳定. using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;usi

配送短信猫软件丰富,支持短信猫二次开发

配送短信猫软件丰富,支持短信猫二次开发 短信猫主要是用于二次开发领域,支持将短信收发功能集成.嵌入到其他系统.软件当中.最终实现短信收发除了需要有短信猫硬件外还需要相应短信猫软件的支持,即所谓的短信猫开发包.短信猫SDK或短信猫接口程序.而支持短信猫二次开发的软件非常丰富,有不同款式.有免费有收费,采用不同开发方式. 以下介绍我公司的几款短信猫开发软件,如下: 免费短信猫DLL开发包 提供有多种开发语言示例DEMO,方便程序员开发调用,免费短信猫开发包,免加密狗,自行测试调试使用. 短信服务器8

短信猫二次开发接口支持任何一种开发语言性能稳定

此款短信猫二次开发接口基于数据库开发方式支持任一种开发语言对短信猫开发,兼容性强.开发简单方便.灵活.稳定.可以快速地使您的应用系统实现短信功能,多种接口方式供二次开发时选择,系统具备良好的可扩展性.企事业单位通过此款短信猫二次开发接口方式实现短信功能,既实现了资源的共享和有效使用,便于企业对进出信息的管理.监控和统计,同时为以后短信功能的扩展提供了便利. 短信猫二次开发接口软件运行界面如图: 在该方案中,考虑到银行是对信息安全性要求很高的行业,采用短信猫作为短信收发设备,避免了常用的通过移动互

Linux系统下配置短信猫

我们的安装系统: redhat linux as 4 2.6.9 功能:通过服务器上的外接modem,利用gnokii发送短信. 安装的软件:gnokii 硬件:gprs modem 设备一个,电话卡一张 我在安装gnokii 之前,必须安装gettext-devel-0.14.1-13.i386.rpm gnokii通过sim卡发送短信,他主要是linux下面用来管理nokia手机的一个软件,当然所有支持AT指令的都可以使用. linux上面安装好gnokii之后,/etc/gnokiirc是

多口短信猫设备及相应二次开发接口程序

多口短信猫是指具备同时插入多张SIM卡使用的短信猫设备,具备单口短信猫8-16倍的短信收发效率,可满足对短信发送.接收量大的客户的应用需求.同样,借助相应的短信猫开发接口程序可以将多口短信猫应用于其他系统.软件当中. 多口短信猫设备有: 8口多口短信猫池,支持同时插入8张SIM卡使用 16口多口短信猫池设备,采用独立电源,一根USB数据线连接 多口短信猫开发接口程序与单口短信猫开发有所不同,大多购买短信猫设备提供的DLL免费短信猫开发包仅支持单口短信猫设备,不支持多口短信猫,所以多口短信猫二次开

短信猫验证码接收解决方案(提供三款接口应用软件)

短信猫验证码方案介绍: 两个短信猫验证的应用场景: 1.网站验证码用户登录 目前在网络上各种网站.应用.平台登录都需要用到手机验证码,直接给用户手机发送验证码后才能进行登录等操作及大地提高了用户的安全性及降低了恶意注册的可能性. 2.网络营销账号注册 我们注册各类网站.APP.软件时均需要与用户手机号绑定才能使用相应的网站和软件功能,有这样一群以出售账号即通过专业的短信猫设备可大批量接收验证码的方式去注册海量账号从而提供给那些网络营销公司或个人,他们可拿来做营销宣传与推广,一个账号的价值不菲.

深圳短信猫厂家自带短信猫开发包支持多种开发语言

深圳最早从事短信猫生产与销售的短信猫厂家-深圳百利通科技,是深圳短信猫厂家中质量上乘.服务周到的正规公司.提供有丰富短信猫开发软件包及接口程序,支持GSM MODEM短信猫二次开发,可广泛用于二次开发领域,将sms.dll文件拷贝到系统安装目录中的system32文件夹中,然后再根据以下接口函数说明和提供的例程源码开发.支持多种程序短信开发语言如:C#.delphi.VC++等,并提供有程序开发示例DEMO,方便参考.实现快速短信二次开发应用.多应用于如OA.ERP.用友.金蝶等办公系统的短信功

配送短信猫二次开发接口提供多种开发语言示例

免费配送的信猫二次开发接口提供有多种开发语言示例,如C#.C++.Delphi.PowerBuilder.VB.net.VC++.VisualBasic等多种开发示例方便程序开发人员开发调试.使用简单方便,将sms.dll文件拷贝到系统安装目录中的system32文件夹中,然后再根据以下接口函数说明和提供的例程源码开发,无需安装,免加密狗. 短信猫二次开发接口提供的开发语言示例有: 部分短信猫二次开发接口函数说明: 1.Sms_Connection(Com_Port As Integer,Com

什么是短信猫

你要问我科普是谁,额......,谁知道是哪国总统,你要问我静静是谁,估计还能告诉你!(偷笑) 科普!科普!科普!重要的事情说三遍! 是不是觉得头重脚轻.腰酸背痛.四肢麻木.昏昏欲睡.闷闷不乐,这就对啦,这就是节后综合征.哈哈,不过小编不是医生,生病还得看医生!是不是觉得小编一改往日风格,嗯,您已在心底默默地抢答了,是!应广大客户和擦边客户的要求,在这阳光灿烂的日子科普下什么是短信猫. 一.短信猫 短信猫其实是一种用来收发短信的设备,他和我们用的手机一样,需要手机SIM卡的支持,在需要收发短信的