代码没有错误就没有报错啊,用try,catch也抓不出来,没有错误
解决方案 »
- 《学OpenGL编游戏》中的MD2动画模型 LINK : fatal error LNK1104: 无法打开文件“libcp.lib
- 请问下,DEBUG版本和RELEASE版本莫非释放指针有不一样吗?
- vc自绘菜单中,菜单项如何响应鼠标左键输入?请高手指点
- 如何判断WM_PAINT消息是由Invalidate函数产生的 谢谢
- 为什么我给对话框的控件变量(值对应)赋值后,对话框显示时却为空呀?
- opengl中绘制多边形平面的方法
- 谁有CJ608 LIB或是CJ609 LIB,急!!!!!!!
- 关于内存映射文件的讨论
- 发现一个问题
- 求一个CSDN下载链接,关于基于MFC对话框下的OpenGL三维模型开发
- mfc如何对编好的界面,对话框,按钮等,进行美化?有没有好的例子,方法,求指导啊!
- 关于CString.Format 的e% 输出格式问题
就是说,我两台主机之间不能有路由器??
就是说,我两台主机之间不能有路由器??
这句话不能这么确定,但是我看你的情况应该是由于路由器隔断导致的,集线器连接应该是没有问题的。
就是说,我两台主机之间不能有路由器??
这句话不能这么确定,但是我看你的情况应该是由于路由器隔断导致的,集线器连接应该是没有问题的。
哦~意思就是可能是路由器影响通信了,所以连接不上?这样,那有什么方式能够确定是不是路由器的问题吗?cmd的指令什么的?
2)tcp本身是可以跨越路由器的,之所以有的路由器跨越不了,
是因为端口映射导致的,很多台机器共用一个ip对外访问,其中使用不同的端口来区分,外部是不能直接连接内部的任何一个ip的。
你如果非要验证自己代码正确性,找个局域网的机器测试一下代码就知道可不可以了。
cmd指令之类的是没有的,与路由器配置有关系。
2、我确定两台电脑没有任何端口映射
3、我们两个主机就是在一个局域网里面
你用的ip地址可以是“192.168.1.1”到“192.168.1. 254
是,一个是192.168.1.171,一个是192.168.1.82
如果这样的话,应该是可以连通的,你最好把代码贴上来看看
好,麻烦给我看看哈~void Cserver_mfcDlg::OnBnClickedListen()//监听本地端口
{
// TODO: 在此添加控件通知处理程序代码
m_hThread_Server=CreateThread(NULL,100,Thread_Server,(void*)this,NULL,NULL); //建立本地服务器端线程监听
}
DWORD Cserver_mfcDlg::Thread_Server(LPVOID lpParam)
{ Cserver_mfcDlg *dlg=(Cserver_mfcDlg*)AfxGetApp()->GetMainWnd();
dlg->MessageBox(_T("thread_server!"),_T("tip"));
dlg->lsn_port.GetWindowTextA(dlg->lsn_port_str); //获取端口号
int server_port=0;
ACE::init();
if(dlg->lsn_port_str=="")
{
server_port=10000; //如果没填,则默认10000号 }
else
{
server_port=_ttoi(dlg->lsn_port_str);
}
ServerAddr.set(server_port,"localhost");
if(ServerAcceptor.open(ServerAddr,1)!=0) //绑定端口
{
//cout<<"band port failed!"<<endl;
dlg->MessageBox(_T("band port failed!"),_T("band tip"));
//return -1;
}
else
{
dlg->MessageBox(_T("band port success!"),_T("band tip"));
ACE_Time_Value timeout(20,0);
if(ServerAcceptor.accept(ServerPeer)==-1) //与客户端建立连接
{
dlg->MessageBox(_T("server connect failed!"),_T("band tip"));
}
else
{
dlg->MessageBox(_T("server connect success!"),_T("band tip"));
while((s_rev_byte=ServerPeer.recv(serverbuf,sizeof(serverbuf)))!=-1)
{
ACE_INET_Addr rome_addr;
ServerPeer.get_local_addr(rome_addr); //获取远端连接ip
CString str_buf;
dlg->msg_record_str+=rome_addr.get_host_name();
str_buf=serverbuf;
str_buf=":"+str_buf.Left(s_rev_byte)+"\r\n";
//str_buf.Format("%s%s",buf,"\n"); //获取接受消息内容
dlg->msg_record_str+=str_buf;
dlg->msg_record.SetWindowTextA(dlg->msg_record_str); //在窗口中显示
}
}
ACE_Thread_Manager::instance ()->cancel_all ();
ACE_Time_Value timeout2(30);
ACE_Thread_Manager::instance()->wait(&timeout2);
ACE::fini();
return NULL;
}void Cserver_mfcDlg::OnBnClickedConnect() //客户端连接
{
// TODO: 在此添加控件通知处理程序代码 ACE_LOCALHOST "192.168.1.82"
ACE::init();
//UpdateData(FALSE); //获取需要连接的对方的ip
CString str_ip="";
int client_port=0;
remote_ip.GetAddress(remote_C_IP);
con_port.GetWindowTextA(con_port_str);
if(remote_C_IP==0)//如果没有输入指定连接ip,则默认192.168.1.171
{
str_ip="192.168.1.82";
}
else
{
remote_ip.GetAddress(remote_C_IP); //获取输入的ip
str_ip.Format("%d.%d.%d.%d",(remote_C_IP>>24)&0xff,
(remote_C_IP>>16)&0xff,
(remote_C_IP>>8)&0xff,
(remote_C_IP)&0xff);
}
if(con_port_str=="")
{
client_port=10000;
}
else
{
client_port=_ttoi(con_port_str);
}
ClientAddr.set(client_port,str_ip); //需连接对方服务器的ip 就是这里有问题
//ACE_SOCK_Connector connector;
ACE_Time_Value timeout(10,0);
//ACE_SOCK_Stream str_send;
ofstream logstream ("./error.log"); //输出错误信息
//MessageBox("connection success!","connection tip");
if(connector.connect(ClientPeer,ClientAddr,&timeout)==-1)
{
MessageBox("client connection failed!","connection tip");
//logstream<<str_send;
//log
//int errorno;
//strerror(errno);
ACE_LOG_MSG->msg_ostream (&logstream);
ACE_DEBUG((LM_INFO, ACE_TEXT ("some text\n")));//此处无输出
logstream<<"test again\n";
logstream<<strerror(errno); //此处输出为no error
}
else
{
MessageBox("client connection success!","connection tip");
//m_hThread_Client=CreateThread(NULL,100,Thread_Client,(void*)this,NULL,NULL);
}
ACE::fini();
}
ServerAddr.set(server_port,"localhost");
localhost使用的127.0.0.1,只能收到来自本机的连接
应该用0.0.0.0
你可以用netstat查看当前的端口使用情况,看看是不是绑定的127.0.0.1