Client socket sending data only one time.

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 24 21:38:05 PDT 2015


On Thursday, 24 September 2015 at 14:20:39 UTC, holo wrote:
> Hello
>
> I'm trying to connect to server and send data, with such simple 
> client:
>
> #!/usr/bin/rdmd
>
> import std.stdio;
> import std.socket;
> import std.socketstream;
> import std.process;
> import std.conv;
> import core.time;
>
> void main()
> {
>         char[1024] buffer = 0;
>
>         Socket client = new TcpSocket();
>         auto addrServer = new InternetAddress("localhost", 
> 8080);
>         client.connect(addrServer);
>
>         while(1)
>         {
>
>                 client.send(readln());
>                 client.receive(buffer);
>                 writeln(buffer);
>                 buffer = 0;
>          }
> }
>
> It is working but only one time, when I'm trying to send again 
> (second loop of while) it's stooping on readln() but not 
> sending input data.
>
> What am i missing here?
>
> Thanks in advance for any help.

Where is the other side of this client? There must be a TCP 
Server to listen connections, and create a second TCPSocket for 
communication. There is only one TCPSocket in your code. A lot of 
things are missing there. I would suggest you to check "C 
TCPSocket example" in your favourite search engine.


More information about the Digitalmars-d-learn mailing list