Socket客户端的问题...
小弟刚刚接触VC,现在需要写一个VC的程序,去给一个Socket Server发一点测试数据。小弟做个一个对话框,上面有一个按钮,想点击这个按钮,就向Socket Server发一条测试数据。
代码是这样写的,可是有问题,请指导一下小弟。
编译的时候就报错:
ClientDlg.cpp(212) : error C2228: left of '.Create' must have class/struct/union type
ClientDlg.cpp(213) : error C2228: left of '.Connect' must have class/struct/union type
ClientDlg.cpp(215) : error C2228: left of '.Send' must have class/struct/union type
代码如下:
#include <afxsock.h>
#include"winsock.h"
#pragma comment(lib,"wsock32")
...
void CClientDlg::OnConnect()
{
// TODO: Add your control notification handler code here
if (!AfxSocketInit())
{
AfxMessageBox("Socket 初始化失败!");
return;
}
SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);//,newsock;
sock.Create();
sock.Connect("192.168.0.100",8086);
char buf[]="Test";
sock.Send(buf,sizeof(buf));
}
能帮小弟改一下吗??