我如何使用std.socket和std.socketstream? (D编程语言2.x)

时间:2022-05-13 04:49:54

i was wondering how to use those phobos modules to use networking?

我想知道如何使用这些phobos模块来使用网络?

Or you can give a reference to how to use sockets (in a way similar or almost similar to D)

或者您可以参考如何使用套接字(以类似或几乎类似于D的方式)

2 个解决方案

#1


std.socket.Socket is essentially a semi-thin wrapper around your operating system's native socket functions. For that reason, I recommend understanding the basics of socket programming in C first - there are plenty of examples for that - then, the std.socket API should be trivial.

std.socket.Socket本质上是围绕操作系统的本机套接字函数的半瘦包装器。出于这个原因,我建议首先了解C语言中套接字编程的基础知识 - 有很多例子 - 然后,std.socket API应该是微不足道的。

For reference: http://digitalmars.com/d/2.0/phobos/std_socket.html

供参考:http://digitalmars.com/d/2.0/phobos/std_socket.html

#2


from memory

auto MyStream = new SocketStream(new Socket(new TcpAddress("stakoverflow.com", 80)));

#1


std.socket.Socket is essentially a semi-thin wrapper around your operating system's native socket functions. For that reason, I recommend understanding the basics of socket programming in C first - there are plenty of examples for that - then, the std.socket API should be trivial.

std.socket.Socket本质上是围绕操作系统的本机套接字函数的半瘦包装器。出于这个原因,我建议首先了解C语言中套接字编程的基础知识 - 有很多例子 - 然后,std.socket API应该是微不足道的。

For reference: http://digitalmars.com/d/2.0/phobos/std_socket.html

供参考:http://digitalmars.com/d/2.0/phobos/std_socket.html

#2


from memory

auto MyStream = new SocketStream(new Socket(new TcpAddress("stakoverflow.com", 80)));