帮小弟我看看这两段程序,为什么传出去的值是空的,(关于CSocket)

帮我看看这两段程序,为什么传出去的值是空的,(关于CSocket)
服务器端
void   CN1Dlg::OnButton1()  
{
CSocket   asocket;
CSocket   pServer;
LPCTSTR   address= "127.0.0.1 ";
//FD_READ|FD_WRITE|FD_OOB|FD_ACCEPT|FD_CONNECT|FD_CLOSE,
asocket.Create(15000);
asocket.Listen();
asocket.Accept(pServer);
LPVOID   lpBuf=0;
pServer.Receive(lpBuf,200,0);
CString   str;
str.Format(_T( "%s "),lpBuf);
MessageBox(str);
}

客户端
void   CN2Dlg::OnButton1()  
{
CSocket   asocket;
asocket.Create();
asocket.Connect(_T( "192.168.0.16 "),15000);
CString   str;
str=_T( "abcdef ");
asocket.Send(str,str.GetLength(),0);
}




------解决方案--------------------
lpBuf没有分配内存。
str.GetBuffer()获得数据指针发送。
------解决方案--------------------
最大的问题就是LPVOID lpBuf=0;其中的lpBuf要的是一个缓冲区的指针.
按如下改完就OK了.
服务器:
void CSvrDlg::OnButton1()
{
// TODO: Add your control notification handler code here
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD( 2, 2 );

err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}

/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */

if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}
CSocket asocket;
CSocket pServer;
LPCTSTR address= "127.0.0.1 ";
//FD_READ|FD_WRITE|FD_OOB|FD_ACCEPT|FD_CONNECT|FD_CLOSE,
asocket.Create(15000);
asocket.Listen();
asocket.Accept(pServer);
/* CString str;
pServer.Receive(str.GetBuffer(200),200,0);
str.ReleaseBuffer();
// CString str;
// str.Format(_T( "%s "),lpBuf);*/
CHAR lpBuf[200];
pServer.Receive(lpBuf,200,0);
CString str;
str.Format(_T( "%s "),lpBuf);

MessageBox(str);
pServer.Close();
asocket.Close();
WSACleanup();
}

客户端:
void CCltDlg::OnButton1()
{
// TODO: Add your control notification handler code here
WORD wVersionRequested;
WSADATA wsaData;
int err;

wVersionRequested = MAKEWORD( 2, 2 );

err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}

/* Confirm that the WinSock DLL supports 2.2.*/
/* Note that if the DLL supports versions greater */
/* than 2.2 in addition to 2.2, it will still return */
/* 2.2 in wVersion since that is the version we */
/* requested. */

if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
WSACleanup( );
return;
}
CSocket asocket;