UDP传输数据问题,为什么受不到信息 ( 积分: 50 )

  • 主题发起人 主题发起人 haoyunp
  • 开始时间 开始时间
H

haoyunp

Unregistered / Unconfirmed
GUEST, unregistred user!
一个很简单的小程序,为什么在别的机器上都能受到信息,就一台收不到,网上邻居能
访问到该机器。
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int I;
AnsiString C;
TMemoryStream * MyStream =new TMemoryStream();
C=Edit1->Text;
I=C.Length();
MyStream->Write(&C[1],I);
NMUDP1->LocalPort=10061;
NMUDP1->RemotePort=10061;
NMUDP1->ReportLevel=Status_Basic;
NMUDP1->RemoteHost=Edit2->Text;//"192.168.0.255";// "zmn";;
NMUDP1->SendStream(MyStream);
delete MyStream;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMUDP1DataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
char *TmpBuffer=new char [NumberBytes+1];
AnsiString cs1;
int i;
TMemoryStream * MyStream =new TMemoryStream();
AnsiString C;
int I;
NMUDP1->ReadBuffer(TmpBuffer,NumberBytes,i);
TmpBuffer[NumberBytes]='/0';
RichEdit1->Text=RichEdit1->Text+"Bytes:"+NumberBytes+TmpBuffer;
Edit3->Text=TmpBuffer;
cs1=AnsiString(TmpBuffer);

//-----------关闭
if (cs1=="gb") {Close();}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
NMUDP1->LocalPort=StrToInt(Edit4->Text);
NMUDP1->RemotePort=StrToInt(Edit5->Text);
NMUDP1->ReportLevel=Status_Basic;
}
//---------------------------------------------------------------------------
 
一个很简单的小程序,为什么在别的机器上都能受到信息,就一台收不到,网上邻居能
访问到该机器。
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int I;
AnsiString C;
TMemoryStream * MyStream =new TMemoryStream();
C=Edit1->Text;
I=C.Length();
MyStream->Write(&C[1],I);
NMUDP1->LocalPort=10061;
NMUDP1->RemotePort=10061;
NMUDP1->ReportLevel=Status_Basic;
NMUDP1->RemoteHost=Edit2->Text;//"192.168.0.255";// "zmn";;
NMUDP1->SendStream(MyStream);
delete MyStream;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMUDP1DataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
char *TmpBuffer=new char [NumberBytes+1];
AnsiString cs1;
int i;
TMemoryStream * MyStream =new TMemoryStream();
AnsiString C;
int I;
NMUDP1->ReadBuffer(TmpBuffer,NumberBytes,i);
TmpBuffer[NumberBytes]='/0';
RichEdit1->Text=RichEdit1->Text+"Bytes:"+NumberBytes+TmpBuffer;
Edit3->Text=TmpBuffer;
cs1=AnsiString(TmpBuffer);

//-----------关闭
if (cs1=="gb") {Close();}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
NMUDP1->LocalPort=StrToInt(Edit4->Text);
NMUDP1->RemotePort=StrToInt(Edit5->Text);
NMUDP1->ReportLevel=Status_Basic;
}
//---------------------------------------------------------------------------
 
请大家帮帮忙
 
192.168.0.255 //这是个广播地址,有可能他禁止了广播消息
 
可是直接给计算机名或ip地址也不可以
还可能是他设置了什么?
 
接受答案了.
 
后退
顶部