在DELPHI中知道对方的IP,怎样向他发送信息?(50分)

  • 主题发起人 主题发起人 dfo_u
  • 开始时间 开始时间
D

dfo_u

Unregistered / Unconfirmed
GUEST, unregistred user!
公司内局域网,分有固定的IP。在DELPHI中知道对方的IP,怎样向他发送信息?(就是像SHOWMESSAGE)
双方都是WIN98。
 
这样那边得有接收处理的服务,然后在写客户端。用TNMMsg,和TNMGeneralServer即可
(在Delphi6,的FastNet上)。
在局域网中你也可以用windows自带的NetSend小程序(这要求是基于WinNT).
 
//对照程序,添加相应的控件
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Psock, NMMSG;

type
TForm1 = class(TForm)
NMMsg1: TNMMsg;
NMMSGServ1: TNMMSGServ;
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit2: TEdit;
Edit3: TEdit;
bntsend: TButton;
StatusBar1: TStatusBar;
procedure bntsendClick(Sender: TObject);
procedure NMMsg1MessageSent(Sender: TObject);
procedure NMMsg1Connect(Sender: TObject);
procedure NMMsg1ConnectionFailed(Sender: TObject);
procedure NMMsg1Disconnect(Sender: TObject);
procedure NMMsg1HostResolved(Sender: TComponent);
procedure NMMsg1Status(Sender: TComponent; Status: String);
procedure NMMsg1InvalidHost(var Handled: Boolean);
procedure NMMSGServ1MSG(Sender: TComponent; const sFrom, sMsg: String);
procedure NMMSGServ1ClientContact(Sender: TObject);
procedure NMMSGServ1Status(Sender: TComponent; Status: String);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.bntsendClick(Sender: TObject);
begin
NMMsg1.Host :=edit3.text;
NMMsg1.FromName :=edit2.text;
NMMsg1.PostIt (edit1.text);//发送信息
end;

procedure TForm1.NMMsg1MessageSent(Sender: TObject);
begin
showMessage('Message sent!');
end;

procedure TForm1.NMMsg1Connect(Sender: TObject);
begin
StatusBar1.SimpleText :='连接成功connection';
end;

procedure TForm1.NMMsg1ConnectionFailed(Sender: TObject);
begin
showmessage('Connection Failed连接失败');
end;

procedure TForm1.NMMsg1Disconnect(Sender: TObject);
begin
If StatusBar1<>nil then
StatusBar1.SimpleText :='Disconnected';
end;

procedure TForm1.NMMsg1HostResolved(Sender: TComponent);
begin
StatusBar1.SimpleText :='Host Resolved';
end;

procedure TForm1.NMMsg1Status(Sender: TComponent; Status: String);
begin
If StatusBar1<>nil then
StatusBar1.SimpleText :=status;
end;

procedure TForm1.NMMsg1InvalidHost(var Handled: Boolean);
var
TmpStr:string;
begin
If InputQuery('Invalid Host!','Specify a new host:',TmpStr)then
begin
NMMsg1.Host :=TmpStr;
Handled:=True;
end;
end;

procedure TForm1.NMMSGServ1MSG(Sender: TComponent; const sFrom,
sMsg: String);
begin
Memo1.Lines.Add ('Message From:'+sFrom);//发送者姓名
Memo1.lines.add(#9+'From IP:'+NMMSGServ1.remoteIP);//ip地址信息
memo1.lines.add(#9+'Message:'+sMsg);//实际信息
end;

procedure TForm1.NMMSGServ1ClientContact(Sender: TObject);
begin
NMMsgServ1.ReportLevel :=Status_Basic;
NMMsgServ1.TimeOut :=90000;
StatusBar1.SimpleText :='Client connected';
end;

procedure TForm1.NMMSGServ1Status(Sender: TComponent; Status: String);
begin
If StatusBar1<>nil then
StatusBar1.SimpleText :=status;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.text:='';
edit2.text:='';
edit3.text:='';
memo1.text:='';
end;

end.
 
clientsocket.Socket.SendText(message);
 
感谢各位的大力支持!
to:春意 请问TNMMsg, TNMMSGServ 控件在哪里?
还有那个EDIT2中的信息是作何用的?望赐教,THANKS!
 
写程序实现的方法挺多,不过好像得有server,client,每台机子都得装
要不你试试98下的winpopup(在开始运行中直接。。)
 

Similar threads

后退
顶部