急!求大神帮忙!!从客户端传一张70M左右的图片到服务器!!调了几天没调出来!!

客户端:
Client->Active = true;
//Application->ProcessMessages();
ShowMessage("send");
TMemoryStream *pMS = new TMemoryStream();
f = new TStringList();
pMS->LoadFromFile(Edit1->Text);
int bmpsize = pMS->Size;
int count = bmpsize/(BUFSIZE-8);
int mod = bmpsize%(BUFSIZE-8);
int ret;
for(i=0;i {
memset(buf,'\0',sizeof(buf));
//包头
buf[0] = 0xFD;
buf[1] = 0xFD;
buf[2] = 0xFD;
buf[3] = 0xFD;
buf[4] = 0x00;
buf[5] = 0x0B;
//图片内容
pMS->ReadBuffer(buf+6,BUFSIZE-8);
//包尾
buf[BUFSIZE-2] = 0xFD;
buf[BUFSIZE-1] = 0x0D;
ret = Client->Socket->SendBuf(buf,BUFSIZE);
while(ret <= 0)
{
errcount++;
ret = Client->Socket->SendBuf(buf,BUFSIZE);
}
f->Add(ret);
Sleep(10);
}
//最后的不完整包
if(mod != 0)
{
memset(buf,'\0',sizeof(buf));
buf[0] = 0xFD;
buf[1] = 0xFD;
buf[2] = 0xFD;
buf[3] = 0xFD;
buf[4] = 0x00;
buf[5] = 0x0B;
pMS->ReadBuffer(buf+6,mod);
buf[6+mod] = 0xFD;
buf[7+mod] = 0x0B;
ret = Client->Socket->SendBuf(buf,mod+8);
while(ret <= 0)
{
errcount++;
ret = Client->Socket->SendBuf(buf,mod+8);
}
f->Add(mod);
f->SaveToFile("f:\send.txt");
}
f->Add(ret);

ShowMessage("发送完成");

delete pMS;
delete f;
Client->Active = false;

服务端:
if(0 == flag)
{
fd = fopen("F:\RAD2010\server\image\1.bmp","ab+");
flag = 1;
}
int datalen = Socket->ReceiveLength();
if(datalen >= RECSIZE)
size = RECSIZE;
else
size = datalen;
memset(buf,'\0',sizeof(buf));
int ret = Socket->ReceiveBuf(buf,size);
//判断是否含包头
if(buf[0] == 0xFD && buf[1] == 0xFD && buf[2] == 0xFD && buf[3] == 0xFD)
{
if(begin == 1)
{
memset(temp,'\0',sizeof(temp));
count = 0;
position = 0;
//ShowMessage("err");
}
begin = 1;
head = 6;
}
//判断是否含包尾
if((buf[ret-2] == 0xFD && buf[ret-1] == 0x0D) || (buf[ret-2] == 0xFD && buf[ret-1] == 0x0B))
{
memcpy(temp+position,buf+head,size-head-2);
count = count + size - head - 2;
//把temp中的内容写到文件里面
if(fwrite(temp,count,1,fd) == 1)
{
f->Add(count);
f->SaveToFile("f:\rec.txt");
memset(temp,'\0',sizeof(temp));
}
else
{
ShowMessage("error");
}
position = 0;
head = 0;
begin = 0;
//接收到最后一个包
if(buf[ret-2] == 0xFD && buf[ret-1] == 0x0B)
{
ShowMessage("接收成功");
fclose(fd);
flag = 0;
}
}
else
{
//把内容放到temp缓冲区Byte temp[110*1024]里面
memcpy(temp+position,buf+head,size-head);
position = position + ret - head;
count = count + size - head;
head = 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问