TCP通信,指定 SOCK_STREAM 套接字
接收字符串的时候会有时出现乱码,为何?
数据接收是没问题,没有出现 SOCKET_ERRORtypedef struct
{
char chPath[MAX_PATH+4];
int bTypeFile;
DWORD nfileSize;
}SendInfo;如上结构接收,提取 chPath,断点处 发现 chPath 时而会出现乱码,有没有办法可以判断的?

解决方案 »

  1.   

    我字符串里存放的是路径,有一次怎么就会变成 "G:\the Watch window.brw,When browsing, you can press {BrowseNext} to go to the next definition.txtVC6EN\COMMON\MSDEV98\BIN\IDE\TOOLTIPS.DLL"
      

  2.   

    输出一下发送buffer里的字符串.
      

  3.   

    发送buffer里的字符串检查过了没有问题
      

  4.   

    送buffer里的字符串 检查过的,没有问题,我怀疑是我一边在这里发帖子,一边又回去查看程序运行状况,恰巧每次都是这边点一下,再点程序那边,马上出现问题,出现如上所述的 "G:\the Watch window.brw,When browsing, you can press {BrowseNext} to go to the next definition.txtVC6EN\COMMON\MSDEV98\BIN\IDE\TOOLTIPS.DLL"
    字符串,
    //the Watch window.brw,When browsing//怀疑是网页的东西但是问题还是存在,乱码还是存在,或者么接收过来的全部为空
      

  5.   

    把代码,发给我,我帮你调试:[email protected]
      

  6.   


    buffer要养成清0的好习惯:memset(buffer, 0 ,buffer_len);
      

  7.   

    本帖最后由 wenxy1 于 2008-08-26 17:20:49 编辑
      

  8.   

    先感谢你,不过 memset(buffer, 0 ,buffer_len); 事先我已经处理了
      

  9.   

    源代码,我已收到,我初步调试运行了一下,没出现你所说的乱码问题。
    MyTransFolder\MyTransFolderDlg.cpp(466) 附近,
    MyTransFolder\MyTransFolderDlg.cpp(593) 附近, 
    这两处有SendInfo info,但没问题。发现有一处问题:CString::GetBuffer()调用后,一定要调用CString::GetBuffer();见MSDN描述:
    CString::GetBuffer 
    LPTSTR GetBuffer( int nMinBufLength );
    throw( CMemoryException );Return ValueAn LPTSTR pointer to the object’s (null-terminated) character buffer.ParametersnMinBufLengthThe minimum size of the character buffer in characters. This value does not include space for a null terminator.ResReturns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents.If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions. The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CString operations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.The buffer memory will be freed automatically when the CString object is destroyed. Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 for the length to ReleaseBuffer and ReleaseBuffer will perform a strlen on the buffer to determine its length. ExampleThe following example demonstrates the use of CString::GetBuffer.// example for CString::GetBuffer
    CString s( "abcd" );
    #ifdef _DEBUG
    afxDump << "CString s " << s << "\n";
    #endif
    LPTSTR p = s.GetBuffer( 10 );
    strcpy( p, "Hello" );   // directly access CString buffer
    s.ReleaseBuffer( );
    #ifdef _DEBUG
    afxDump << "CString s " << s << "\n";
    #endif
      

  10.   

    不要用经构体用char *保证不会!
      

  11.   

    不是unicode模式编译的话,建议你用UCHAR代替CHAR吧.