- UID
- 4300
注册时间2005-11-4
阅读权限40
最后登录1970-1-1
独步武林
TA的每日心情 | 开心 2022-7-9 18:18 |
---|
签到天数: 12 天 [LV.3]偶尔看看II
|
- #include <winsock2.h>
- #include <stdio.h>
- void main()
- {
- SOCKET s;
- struct sockaddr_in tcpaddr;
- int port=5567;
- int bbind;
- pid_t pid;
- WSADATA wsadata;
- WSAStartup(MAKEWORD(2,2),&wsadata);
- s=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- tcpaddr.sin_family=AF_INET;
- tcpaddr.sin_port=htons(port);
- tcpaddr.sin_addr.s_addr=htonl(INADDR_ANY);
- bbind=bind(s,(SOCKADDR *)&tcpaddr,sizeof(tcpaddr));
- printf("the bind is %d \n",bbind);
- bbind=listen(s,3);
- printf("it is listen to port %d \n",bbind);
- }
复制代码 照着书上的代码编写socket的程序到这里应该能看到端口了吧?可是我netstat -an的时候看不到我设定的端口处于listen状态。请问高手这是为何?
莫说人品问题/:001 |
|