Socket programming

Regan Heath regan at netwin.co.nz
Wed May 3 15:52:43 PDT 2006


On Wed, 3 May 2006 22:33:38 +0200, the.chojin <the.chojin at nospan.com>  
wrote:
> I am new in D, for my first test I try to develop a simple TCP  
> client/server
> program, but the server side can not receive data and always return
> Socket.ERROR although client side return the good sended bytes number.
>
> If anyone can help me.

<snip>

>   listener.accept();

"accept" returns a new socket, i.e.

Socket s = listener.accept();

You should then read from s, eg.

>   printf("Connected\n");
>
>   while( erreur != 0 && erreur!= Socket.ERROR ) {
>
>    /* read the socker buffer */
>    erreur = s.receive(buffer);
>
>    if( Socket.ERROR  != erreur ) {
>     printf("Received %d bytes : %.*s\n", cast(int)erreur,
> buffer[0..erreur]);
>    } else {
>     printf("Error during receiving\n");
>    }

Regan



More information about the Digitalmars-d-learn mailing list