我正在从客户端向服务器发送数据,但图片没有收到完整的。
客户代码:
FILE *fr = fopen(tmppicsend, "rb");
char* buffer;
buffer = (char*) malloc(sizeof(char)*size);
fread(buffer, size, 1, fr);
send_len_pic = send( m_socket_pic, buffer, size, 0 );
recv( m_socket_pic, rec_end_check, 32, 0 );
fclose(fr);
free(buffer);
服务器代码:
FILE *fw = fopen(fname, "wb");
char* buffer;
buffer = (char*) malloc(sizeof(char)*size);
int rec_len = recv( current_client, buffer, size, 0 );
buffer[size]='\0';
fwrite(buffer, size, 1, fw);
size -= size;
free(buffer);
fclose(fw);
配置套接字:
WSADATA wsaData_pic;
SOCKET m_socket_pic;
SOCKET m_backup_pic;
sockaddr_in con_pic;
// Initialize Winsock.
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData_pic );
if ( iResult != NO_ERROR ){
//printf("Error at WSAStartup()\n");
}
// Create a socket.
m_socket_pic = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket_pic == INVALID_SOCKET ) {
//printf( "Error at socket(): %ld\n", WSAGetLastError() );
//WSACleanup();
}
m_backup_pic = m_socket_pic;
// Connect to a server.
con_pic.sin_family = AF_INET;
con_pic.sin_addr.s_addr = inet_addr( ip );
con_pic.sin_port = htons( 2200 );
if ( connect( m_backup_pic, (SOCKADDR*) &con_pic, sizeof(con_pic) ) == SOCKET_ERROR) {
//printf( "Failed to connect.\n" );
//WSACleanup();
}else
{
m_socket_pic=m_backup_pic;
}
}
当我比较这些图片时,我看到序列号数据包中有错误(数据包没有定期接收)。图片(来自客户端和服务器的图片)大小相同。我想发送JPEG图片。
请帮助我,坦克。