nmudp控件的使用
如何使用NMUDP控件,往局域网电脑的显示器上发送简单消息,比如“XXX你妈喊你回家吃饭”...滚动几秒后消失
NMUDP帮助不是很详细,对网络编程也不是很熟,需要配置什么才能在局域网广播这样的消息。。。
麻烦大侠不吝赐教...
[解决办法]
//---------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//发送的UDP控件
NMUDP1->RemoteHost = "127.0.0.1";
NMUDP1->RemotePort = 8001 ;
//接收的UDP控件
NMUDP2->LocalPort = 8001 ;
}
//---------------------------------------
void __fastcall TForm1::NMUDP2DataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
char TmpBuffer[1024]={0};
int i;
NMUDP2->ReadBuffer(TmpBuffer,NumberBytes,i);
TmpBuffer[NumberBytes]= '\0 ';
Memo1->Lines->Add(TmpBuffer);
}
//---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *ch = "你好";
NMUDP1-> SendBuffer(ch,sizeof(ch),sizeof(ch));
}
//---------------------------------------