Home > Back-end >  CBuilder6.0 using NMUDP control program written UDP sends, can only send data of 8 k, expert guidanc
CBuilder6.0 using NMUDP control program written UDP sends, can only send data of 8 k, expert guidanc

Time:09-26

CBuilder6.0 using NMUDP control program written UDP sends, can only send data of 8 k, please expert guidance, stick the HTML code is as follows:
//send data
Void __fastcall TForm1: : Button2Click (TObject * Sender)
{
If (Edit1 - & gt; Text=="")
{
ShowMessage (" please select a file to transfer!" );
return;
}
If (Edit2 - & gt; Text=="" | | Edit3 - & gt; Text=="")
{
ShowMessage (" please fill in the right to the remote host IP and port number ");
return;
}

NMUDP1 - & gt; RemoteHost=Edit2 - & gt; The Text;
NMUDP1 - & gt; RemotePort=StrToInt (Edit3 - & gt; The Text);

NMUDP1 - & gt; ReportLevel=Status_Basic;
Memo2 - & gt; The Clear ();
//load the file stream
TFileStream * Strm=new TFileStream (Edit1 - & gt; Text, fmOpenRead);
Const int bufLength=2048;
Char * Buffer=new char [bufLength];
Int BuffSize=Strm - & gt; The Size;
Int Buf=BuffSize/bufLength;

for(int i=0; i{
If (BuffSize> BufLength)
{
Strm - & gt; Read (Buffer, bufLength);
NMUDP1 - & gt; SendBuffer (Buffer, bufLength bufLength);
}
The else
{
Strm - & gt; Read (Buffer, BuffSize);
NMUDP1 - & gt; SendBuffer (Buffer, BuffSize BuffSize);
}
BuffSize=BuffSize - bufLength;
}

Delete Buffer;
Delete the Strm;

The receiver
Void __fastcall TForm1: : NMUDP1DataReceived (TComponent * Sender,
Int NumberBytes, AnsiString FromIP, int Port)
{
Char * TmpBuff=new char [NumberBytes + 1];
Int I;
//read the received file flow
NMUDP1 - & gt; ReadBuffer (TmpBuff NumberBytes, I);
TmpBuff [NumberBytes]='\ 0';
Memo2 - & gt; Text=Memo2 - & gt; The Text + TmpBuff;
Int iFileHandle;
if(! FileExists (" E: \ \ dd. TXT "))
IFileHandle=FileCreate (" E: \ \ dd. TXT ");
The else
{
IFileHandle=FileOpen (" E: \ \ dd. TXT ", fmOpenReadWrite);
}

FileSeek (iFileHandle, 0, 2);
FileWrite (iFileHandle TmpBuff, NumberBytes + 1);
FileClose (iFileHandle);
The delete TmpBuff;
}

CodePudding user response:

Isn't too simple there is no answer good sad ~ ~...

CodePudding user response:

8 k because of the limitation of network hardware, better network hardware needs to be replaced

CodePudding user response:

Several times can send

CodePudding user response:

I was divided into 2048 bytes in the transmission, but only 8 k, so depressed, said hardware limited is unlikely, all what s just a switch should be more than 8 k, I asked the colleagues, he said nic cache is 8 k, should be related to this, but he doesn't have time also scrutinize

CodePudding user response:

What age, there are those who actually used NMUDP development UDP communication program,

Can surely have a dime relationship with the hardware, preliminary swept the code, if there is no error code itself (never used NMUDP this garbage, recommend you use ICS asynchronous components, ICS website can download), may be due to packet loss and is not recommended in receive events every time data to re-open or new files, suggest to open the file or create a new action to outside events ready in advance, so every time when positioning the end of the file data can be written, and, of course, can also be NMUDP itself is not perfect the reason why you use shall not method, temporarily not in consideration,
  • Related