?我不能和INTERNET的朋友聊?(30分)

  • 主题发起人 主题发起人 41426277
  • 开始时间 开始时间
4

41426277

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我的程序
unit Unit1;

interface

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

type
TForm1 = class(TForm)
NMUDP1: TNMUDP;
btnSend: TButton;
Memo1: TMemo;
StatusBar1: TStatusBar;
GroupBox1: TGroupBox;
btnLoad: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
btnSave: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
btnSet: TButton;
procedure NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
procedure btnSendClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnLoadClick(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnSetClick(Sender: TObject);
procedure NMUDP1DataSend(Sender: TObject);
procedure NMUDP1Status(Sender: TComponent; status: String);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
TXT: PChar;
Count: Integer;
begin
StatusBar1.SimpleText:='Receiving data';
GetMem(txt,NUmberBytes+1);
ZeroMemory(TXT,NumberBytes+1);
NMUDP1.ReadBuffer(TXT^, Count);
Memo1.Lines.Add(TXT);
FreeMem(Txt);
StatusBar1.SimpleText:='data Received';
end;

procedure TForm1.btnSendClick(Sender: TObject);
var
txt:pchar;
begin
//valid
if Memo1.Text='' then
begin
StatusBar1.SimpleText:='Nothing to send';
exit;
end;
//infact only 1024 byte can send
GetMem(txt,Length(Memo1.Text)+1);
ZeroMemory(txt,Length(Memo1.Text)+1);
txt:=PChar(Memo1.Text);
//set ip info
NMUDP1.RemoteHost := Edit1.Text;
NMUDP1.RemotePort := StrToInt(Edit2.Text);
//send
NMUDP1.SendBuffer(txt^,Length(Memo1.Text));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//notify
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Memo1.Text:='';
Memo1.ScrollBars:=ssBoth;
StatusBar1.SimpleText:='Load Text File to Send';
//property set
NMUDP1.ReportLevel := Status_Basic;
end;

procedure TForm1.btnLoadClick(Sender: TObject);
var
Ext:string;
begin
if OpenDialog1.Execute then
begin
Ext:=ExtractFileExt(OpenDialog1.FileName);
if Ext<>'.txt' then
begin
ShowMessage('Only Txt File Accepted');
exit;
end;
Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
end;
end;

procedure TForm1.btnSaveClick(Sender: TObject);
begin
if SaveDialog1.Execute then
Memo1.Lines.SaveToFile(SaveDialog1.FileName);
end;

procedure TForm1.btnSetClick(Sender: TObject);
begin
//set info
NMUDP1.LocalPort:=StrToInt(Edit3.Text);
NMUDP1.RemoteHost:=Edit1.Text;
NMUDP1.RemotePort:=StrToInt(Edit2.Text);
end;

procedure TForm1.NMUDP1DataSend(Sender: TObject);
begin
StatusBar1.SimpleText:='Data Send';
end;

procedure TForm1.NMUDP1Status(Sender: TComponent; status: String);
begin
StatusBar1.SimpleText:=Status;
end;

end.
 
我的意思是:我有上面这个UDP程序,
朋友也有上面这个UDP程序.
我们双方用QQ看到对方的IP,然后按对方的IP用UDP程序聊天,不知为什么?双方都接了路由器.
 
我简单地说,就是我的电脑是接了ADSL路由器上网的.
朋友是拔号上网的,
我能不能用上面这个简单的UDP程序,对方也有这个程序,能不能和他们聊天,IP是QQ所得
 
怎么可能,想得那么幼稚!!!还有端口的!而端口你又不知道!!
 
自己开发的当然有端口啦,PORT1:3333,PORT2:4444

 
是不是网络供应商把端口给屏蔽了~
我们这里上QQ只能通过http代理上。
只有80端口开着:(
 
我想应该是路由问题
 
两边的端口应该一样
 

Similar threads

后退
顶部