简体   繁体   English

C ++-XCode和测试端口是否打开

[英]C++ - XCode and Testing if a port is open

So using winsock with c++ under windows is pretty simple. 因此,在Windows下将Winsock与c ++一起使用非常简单。 However, how does one do when you are using Xcode and c++ under mac to test if a port is open? 但是,当您在Mac下使用Xcode和c ++测试端口是否打开时,该怎么办? In this case i'd like to check if the login server is up for my favorite game is up. 在这种情况下,我想检查登录服务器是否已启动,而我最喜欢的游戏是否已启动。

Is there a "native" way of doing this? 有没有一种“本机”的方式来做到这一点? Or does one have to rely on some other 3rd party library to get this working? 还是必须依靠其他一些第三方库才能使这项工作奏效?

Example appriciated, allthough not required. 示例适用,尽管不是必需的。

The best way to test for the availability of any resource is just to try to use it. 测试任何资源的可用性的最佳方法就是尝试使用它。 Looking for tricks that will tell you ahead of time whether the attempted use will succeed are essentially exercises in fortune-telling. 寻找技巧可以提前告诉您尝试使用是否会成功,这实际上是算命的练习。 Just try it and catch the exception/handle the error code. 尝试一下并捕获异常/处理错误代码。 You have to do that anyway: why do it all twice? 无论如何,您都必须这样做:为什么都要两次?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM