dqnek0079 2019-03-27 04:46
浏览 63

检测网络连接可用性更改

I am writing a Go application for Mac and Windows, which will perform some action whenever there is a network change( Client move from Wi-fi 1 to Wi-fi 2 or to 3G to LAN). I am aware of a solution for Application running on mac in swift language but I am looking for a platform-agnostic solution here.

So far I have tried checking for an event on an interface but I am not sure if that is sufficient.

I expect that on a network change (moving from Wifi-1 to Wifi-2 or 3G or LAN) my Go app should be able to know to take some action.

  • 写回答

2条回答 默认 最新

  • doufu2496 2019-03-27 12:52
    关注

    I doubt there would be such a solution.

    Every project which tries to provide some platform-agnostic solution to an inherently OS-tied problem inevitably hides the platform-specific details behind a common API. Look at https://github.com/fsnotify/fsnotify for a good example.

    So, I'd take that route and would have put up a package which would have two platform-specific "backends" which would be compiled conditionally using build tags.

    To get notified about network-related events under Windows, you should probably start here. Unfortunately, this stuff is COM-oriented, but you could use https://github.com/go-ole/go-ole to help with that.

    You might also ask a non-Go-specific question tagged winapi to ask about what would be the best way to hook into the kernel to get notified about the availability of the networks.

    评论

报告相同问题?

悬赏问题

  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改