请救我啊,TNMUDP的问题?不断加分中。(没人能回答吗??现在还没有人回答)。。。(先给200分) (200分)

  • 主题发起人 主题发起人 gydsj
  • 开始时间 开始时间
另外,6767似乎是NT Remote Control Port,会不会与此有关?
 
我把它换成5000
 
IP变了,218。10。219。97
 
我发了,收到没有??你也发一个过来我看一下。
 
也发了,我可以看到我发出的包,地址与PORT均正确,但看不到你发来的包。你是用的什么上网?
 
局域网上网。
 
明天再试吧。我的QQ:78994382
 
估计是被防火墙封了
反正我这是发不出去
收不来的
 
to cook:
防火墙没有封。

 
你说服务器可以收到客户的消息,那么
客户端能收到服务器的消息吗??
 
to cook
客户端也能收到服务器端的消息。
 
我又来了,再试一下?
 
我的IP地址跟昨天是一样的。端口还是5000
 
这是我的源代码:
(dfm文件)
object Form1: TForm1
Left = 201
Top = 103
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnShow = FormShow
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 93
Top = 64
Width = 36
Height = 13
Caption = '主机:'
end
object Label2: TLabel
Left = 94
Top = 90
Width = 36
Height = 13
Caption = '端口:'
end
object Label3: TLabel
Left = 96
Top = 128
Width = 36
Height = 13
Caption = '消息:'
end
object Edit1: TEdit
Left = 129
Top = 122
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Memo1: TMemo
Left = 128
Top = 152
Width = 185
Height = 89
Lines.Strings = (
'Memo1')
TabOrder = 1
end
object Button1: TButton
Left = 232
Top = 272
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 2
OnClick = Button1Click
end
object Edit2: TEdit
Left = 128
Top = 56
Width = 121
Height = 21
TabOrder = 3
Text = 'Edit2'
end
object Edit3: TEdit
Left = 128
Top = 88
Width = 121
Height = 21
TabOrder = 4
Text = 'Edit3'
end
object StatusBar1: TStatusBar
Left = 0
Top = 329
Width = 536
Height = 19
Panels = <>
SimplePanel = False
end
object NMUDP1: TNMUDP
RemotePort = 0
LocalPort = 6767
ReportLevel = 1
OnDataReceived = NMUDP1DataReceived
OnStatus = NMUDP1Status
OnBufferInvalid = NMUDP1BufferInvalid
Left = 24
Top = 15
end
end

(unit文件:)

unit Unit1;

interface

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

type
TForm1 = class(TForm)
NMUDP1: TNMUDP;
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Edit3: TEdit;
Label3: TLabel;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
procedure NMUDP1BufferInvalid(var handled: Boolean;
var Buff: array of Char; var length: Integer);
procedure NMUDP1Status(Sender: TComponent; status: String);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
MyStream: TMemoryStream;
vStr: string;
vStrList: TStringList;
begin
NMUDP1.ReportLevel := Status_Basic;
NMUDP1.RemoteHost := Edit2.Text;
NMUDP1.RemotePort := StrToInt(Edit3.Text);
// vStr := Edit1.Text;
vStrList := TStringList.Create;
try
// vStrList.Values['Message'] := Edit1.Text;
vStrList.Text := Edit1.Text;
vStr := vStrList.Text;
try
MyStream := TMemoryStream.Create;
MyStream.Write(vStr[1], Length(vStr));
NMUDP1.SendStream(MyStream);
finally
MyStream.Free;
end;
finally
vStrList.Free;
end;
end;

procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream: TMemoryStream;
vStr: string;
vStrList: TStringList;
begin
MyStream := TMemoryStream.Create;
vStrList := TStringList.Create;
try
try
NMUDP1.ReadStream(MyStream);
SetLength(vStr, NumberBytes);
MyStream.Read(vStr[1], NumberBytes);
vStrList.Text := vStr;
Memo1.Lines.Add(FromIP + ' : ' + vStrList.Text{.Values['Message']} + ' 端口: ' + IntToStr(Port));
finally
MyStream.Free;
end;
finally
vStrList.Free;
end;
end;

procedure TForm1.NMUDP1BufferInvalid(var handled: Boolean;
var Buff: array of Char; var length: Integer);
var
vStr: string;
begin
if InputQuery('无效主机,', '请输入一个新的主机名:', vStr) then
begin
NMUDP1.RemoteHost := vStr;
Handled := True;
end;
end;

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

procedure TForm1.FormShow(Sender: TObject);
begin
NMUDP1.LocalPort := StrToInt(InputBox('端口号', '请输入本机端口号:', '6767'));
Caption := IntToStr(NMUDP1.LocalPort);
end;

end.
 
我重新试验了下,使用IP为
source:218.8.43.45 ADSL
remote:61.189.132.95 拨号
port:3999
防火墙:天网2.48
均可以正常通信。

但如果用局域网方式上网,就会根据代理的不同出现一些丢包的情况。如用小区FTTB方式,
昨天就无法通信,今天正常了(今天用的是QQ的端口)。所以建议你换用一个不太敏感的
port,可能会解决问题(你的源码在我这正常)。
 
我这边测试还是不能通过.
 
remote:61.189.132.95 拨号 是你的IP吗??

 
to netameng
我加你为好友了,我的QQ是147688850
 
后退
顶部