gpt4 book ai didi

C编程使用特定的主机IP连接到服务器

转载 作者:太空宇宙 更新时间:2023-11-03 23:34:35 25 4
gpt4 key购买 nike

我正在查看一台具有多个 IP 地址(例如以太网和无线)的机器,并且需要我的客户端使用特定的客户端 IP 地址连接到服务器。我可以在 Java 中轻松执行此操作(使用 4 个参数完成 Socket()),但我能看到的使用特定主机 IP 地址的唯一引用是使用 bind(),但据我所知,仅使用用于服务器。

简介:客户端有 2 个 IP 地址(以太网和无线)试图连接到服务器..但是使用特定的 IP(不需要担心“查找”IP 地址,因为它们将在配置文件或定义中

不是只有 windows 的答案,而是一个可移植的 C 程序(我通常使用 mac osx/linux,但也使用 windows)

最佳答案

我以前从未这样做过,但我认为您可以将一个套接字绑定(bind)到一个 IP 地址,然后使用与该套接字的连接。相关部分来自这里http://pubs.opengroup.org/onlinepubs/009695399/functions/connect.html状态:

If the socket has not already been bound to a local address, connect() shall bind it to an address which, unless the socket's address family is AF_UNIX, is an unused local address.

这意味着可以在连接之前使用绑定(bind)。

关于C编程使用特定的主机IP连接到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7439500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com