【问题标题】:why does client need the size of the server to connect to it in c [closed]为什么客户端需要服务器的大小才能在c中连接到它[关闭]
【发布时间】:2020-08-20 18:07:08
【问题描述】:

在 python 中,您只需提供 IP 和端口,如 connect(("0.0.0.0", 123))。

但在 c 中是这样的:

connect(s ,(struct sockaddr *)&server , sizeof(server) )

为什么程序需要服务器大小来连接服务器?

【问题讨论】:

  • C 是一种比 Python 低级的语言,它牺牲了一些易于编程的特性,以提高运行时效率。因此,在 Python 中很容易的许多事情在 C 中并不那么容易。

标签: c sockets networking server


【解决方案1】:

connect 调用可以采用几种不同类型的套接字地址结构,例如sockaddr_insockaddr_in6sockaddr_un 等。

传入大小,以便函数知道输入结构的实际大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多