TCP Socket Client Example
Alex Parrill via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 14 07:12:12 PDT 2015
On Friday, 14 August 2015 at 14:06:03 UTC, Kingsley wrote:
> Hi
>
> Does anyone have some examples of making a client socket
> connection to a host on a port and parsing the incoming data in
> some kind of loop.
>
> --K
auto addresses = getAddress("localhost", 8085);
auto socket = new Socket(AddressFamily.INET, SocketType.STREAM,
ProtocolType.TCP);
scope(exit) socket.close();
socket.connect(addresses[0]);
auto buffer = new ubyte[2056];
ptrdiff_t amountRead;
while((amountRead = socket.receive(buffer)) != 0) {
enforce(amountRead > 0, lastSocketError);
// Do stuff with buffer
}
More information about the Digitalmars-d
mailing list