为什么总是错,好奇怪啊

tblue7 2004-01-06 02:26:22
CSocket m;
m.Create(portnum)
m.Listen()
就是这么简单几句话,为什么总返回0
端口我也该了几次了,
望大侠指点!
...全文
36 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tblue7 2004-01-06
  • 打赏
  • 举报
回复
不用CSocket这个类,建立连接的步骤我知道,可是用了CSocket后要用AfxSocketInit()我确不知道,汗,第一次写一个网络方面的就搞得这么狼狈。谢谢各位大哥的指点,程序已经通过了,分少了点,下次多补写:)
checkyvc6 2004-01-06
  • 打赏
  • 举报
回复
AfxSocketInit();
会隐含建立一个窗口来接受消息的
zgh266 2004-01-06
  • 打赏
  • 举报
回复
up
孤必有邻 2004-01-06
  • 打赏
  • 举报
回复
调用与CSocket对应的初始化
AfxSocketInit();
wflyfox 2004-01-06
  • 打赏
  • 举报
回复
需要首先WSAStartup()函数。
int WSAStartup(
WORD wVersionRequested,
LPWSADATA lpWSAData
);


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;
}

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧