1.使用VC++6.0,创建基于对话框的应用程序
2.工程包含afxsock.h头文件
3.在对话框界面拖一个按钮,添加程序
void CFaDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString STR = "10.53.31.175";
//BOOL RET = ClientSc.Create();
BOOL RET = ClientSc.Create(0,SOCK_DGRAM,NULL);
if(ClientSc.Connect(STR,1500))
{
MessageBox("connect successfull!","Msg",0);
}
else
{
MessageBox("connect fail!","Msg",0);
}
}
4.再添加一个按钮,编辑代码
void CFaDlg::OnButton2()
{
// TODO: Add your control notification handler code here
int ret = ClientSc.Send("Hello!/r/n",8);
}
5.打开抓包工具,监视1500端口
6.点击按钮1,创建端口并连接,连接失败
7.在初始化时(使用soket之前)加入以下代码