程序运行后无法连接上
void CClientDlg::OnConnbutton()
{
// TODO: Add your control notification handler code here
UpdateData(true); m_ClientSocket.Create();
if(m_ClientSocket.Connect(m_strIP,m_nPort))
AfxMessageBox("Connect the Server Successful!");
else
AfxMessageBox("Connect the Server Failed!");}
运行后出现Connect the Server Failed这样的弹出对话框,
void CClientDlg::OnConnbutton()
{
// TODO: Add your control notification handler code here
UpdateData(true); m_ClientSocket.Create();
if(m_ClientSocket.Connect(m_strIP,m_nPort))
AfxMessageBox("Connect the Server Successful!");
else
AfxMessageBox("Connect the Server Failed!");}
运行后出现Connect the Server Failed这样的弹出对话框,
解决方案 »
- VC2005/2008可以用COM吗,怎么用
- 公司内部的IP可以做服务器的IP吗??
- 当双击删除树的节点的时候,为什么第二次删除出现错误?
- 谁那有模拟鼠标拖动窗口标题的例子
- 如何得到cwnd的子窗口(包括各种控件如按钮,文字。),只知道该窗口的指针。
- 请教:CTreeCtrl中怎么捕获Check消息?
- 报出信息 Cannot save file. The file may be in use by another application.
- 用vc开发怎么实现 build number?
- 怎样在应用程序中发送HTML格式的邮件
- VC写的光盘刻录程序,怎么不能写入到光盘里去?
- 为什么在CSocket类的OnAccept()函数中,使用Accept()函数,得到的对方的IP地址是204.204.204.204?
- 急救时间格式化问题!!
然后检查
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
是否初始化Socket
..这个类没有用过.要不要指定是tcp还是udp啊?
我是在同一台机器上实现信息传送的,psprite(小皮)
先确定服务器是否启动,监听端口是否正确
然后检查
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
是否初始化Socket的解释不明白,能详细些吗?
{
// TODO: Add your control notification handler code here
UpdateData(true);m_ClientSocket.Create();
if(m_ClientSocket.Connect(m_strIP,m_nPort))
AfxMessageBox("Connect the Server Successful!");
else
AfxMessageBox("Connect the Server Failed!");}
把这段代码改为
void CClientDlg::OnConnbutton()
{
// TODO: Add your control notification handler code here
UpdateData(true);m_ClientSocket.Create();
if(m_ClientSocket.Connect(m_strIP,m_nPort))
AfxMessageBox("Connect the Server Successful!");
else
{
AfxMessageBox("Connect the Server Failed!");
TRACE1("error code = %d\n",GetLastError());
}
}
调试程序看看error code是多少就知道原因啦.
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
return FALSE;
}
这个东西了。建一个类:class CMySvr : public CSocket{。}
用CTRL+W建立起来。CClientDlg里要定义一个SOCKET对象:
CMySvr *m_pSockSvr;最后:
m_pSockSvr = new CMySvr(); //创建对象
UINT nPortSvr = 50000;
if (m_pSockSvr->Create(nPortSvr))
{
Listen();
AfxMessageBox("Connect the Server Successful!"); }
else
AfxMessageBox("Connect the Server Failed!");