0

我在通过网络发送图像时遇到问题。但我不断收到从客户端发送到服务器的错误

( "msvcr110d.dll" Access violation writing location 
 mov     [edi],edx           ; store one more dword c++)

知道什么是错的。

平台:Windows 7 Visual Studio C++ 2012 Express C++

发送和接收消息

(
 string ReceiveMyMessage(SOCKET s1)
{

exception e;
try
{
ZeroMemory(szbuffer,strlen(szbuffer));

if((ibytesrecv = recv(s1,szbuffer,100,0)) == SOCKET_ERROR)
    throw "Receive error in server program\n";

return ((string) szbuffer);
}
catch(exception e)
{

cout<<"似乎客户端已关闭!\n(SendMyMessage) 尝试执行 recv 命令时出错!"<

客户代码:

void SendStreamFile()
 {
_get_printf_count_output();

struct stat myFileState;
int Filesize = 0;
char * myDATA;
FILE *f = fopen(FileName.c_str(),"rb");
Filesize = (int) myFileState.st_size;
myDATA = (char *) malloc(sizeof(char) * Filesize);
fread(myDATA,1,Filesize,f);
fclose(f);

SendMyMessage(to_string( Filesize));
char * ptr;
string strToSend = "";

for (int x = 0; x < Filesize; )
{
    ptr = &myDATA[x];
    strToSend.assign(ptr,20);
    Sleep(100);
    //cout << strToSend <<endl;
    SendMyMessage(strToSend);
    x = x + 20;
    cout << x << " - " << Filesize <<endl;
}

SendMyMessage("*D*");
free(myDATA);
 }

服务器代码:

void ReceiveClientFileStream(string FileName, SOCKET s1)
 {

string Fsize = ReceiveMyMessage(s1);

   int Filesize = 0;
Filesize= atoi(Fsize.c_str());


char * myDATA;
myDATA = new char[Filesize];
   cout << strlen(myDATA) << Filesize <<endl;
//SendMyMessage(to_string( Filesize),s1);
//char * ptr = &myDATA[0];
string str = "";

   //   ZeroMemory(myDATA,Filesize);
do
{
    str = ReceiveMyMessage(s1);
    cout << str << endl;
    if (str.find("*D*") == string::npos)
strcat(myDATA,str.c_str());
    else
        {   
strcat(myDATA,str.substr(str.length()-3, str.length()).c_str());
            break;
    }

}while(1);
FILE * fil;
fil = fopen(FileName.c_str(),"wb");
fwrite(myDATA,sizeof(char),strlen(myDATA),fil);

free(myDATA);

}
4

0 回答 0