在MFC中获取未使用的端口 [英] Getting Un-used port in MFC

查看:102
本文介绍了在MFC中获取未使用的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想为我的CSOcket服务器获取系统中未使用的端口,因为在应用程序启动时我正在运行服务器.我不喜欢我的应用程序在启动时崩溃,这就是为什么我需要为服务器使用未使用的端口的原因.我不知道如何获取未使用的端口列表.

在此先感谢
ganesh_IT

Hi guys,

I want to get the unused ports in my system for my CSOcket server because I am running server at the time of application start up. I don''t like my application crashing at start up that''s why I need unused port for my server. I don''t how to get the list of ports which is unused.

Thanks in advance
ganesh_IT

推荐答案

您是否只能绑定到端口0,这应该会为您提供可用的端口?

http://msdn.microsoft.com/en-us/library/xz019029%28v = vs.80%29.aspx [ ^ ]

nSocketPort
套接字要使用的知名端口,如果要Windows套接字选择端口,则为0.
Can''t you just bind to port 0 which should give you an available port?

http://msdn.microsoft.com/en-us/library/xz019029%28v=vs.80%29.aspx[^]

nSocketPort
A well-known port to be used with the socket, or 0 if you want Windows Sockets to select a port.


您可以使用程序 tcpview 查看程序在端口上运行并使用套接字.
You can use program tcpview to look at programs runing on port and using sockets.


这篇关于在MFC中获取未使用的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆