digitalmars.D.learn - Server side command execution.
- holo (37/37) Sep 27 2015 Hello
- tcak (2/6) Sep 27 2015 You are comparing whole buffer to "exit"
- holo (8/16) Sep 28 2015 I changed my condition to:
- anonymous (2/12) Sep 28 2015 The client probably sends a newline; i.e. buffer[0 .. received] is "exit...
- anonymous (2/4) Sep 28 2015 Or more likely it's "exit\r\n".
- holo (8/12) Sep 28 2015 I changed condition to:
- Adam D. Ruppe (5/6) Sep 28 2015 You shouldn't need that to!string by the way. I believe that will
- holo (2/8) Sep 28 2015 Yep it it like you wrote. Thank you for advice.
Hello Im trying to execute commands on server side. Here is my server based on other example from forum: import std.stdio; import std.socket; import std.algorithm; import std.conv; void main() { Socket server = new TcpSocket(); server.setOption(SocketOptionLevel.SOCKET, SocketOption.REUSEADDR, true); server.bind(new InternetAddress(8080)); server.listen(1); Socket client = server.accept(); while(true) { char[1024] buffer = 0; auto received = client.receive(buffer); writefln("The client said:\n%s", buffer[0.. received]); enum header = "HTTP/1.0 200 OK\nContent-Type: text/html; charset=utf-8\n\n"; string response = header ~ "Hello World!\n"; client.send(response); if(to!string(buffer) == "exit") { break; } } client.shutdown(SocketShutdown.BOTH); client.close(); } When i send "exit" nothing is happening. How it should be done to make it working? //holo
Sep 27 2015
On Sunday, 27 September 2015 at 23:56:10 UTC, holo wrote:Hello Im trying to execute commands on server side. Here is my server based on other example from forum: [...]You are comparing whole buffer to "exit"
Sep 27 2015
On Monday, 28 September 2015 at 04:55:30 UTC, tcak wrote:On Sunday, 27 September 2015 at 23:56:10 UTC, holo wrote:I changed my condition to: if(to!string(buffer[0..received]) == "exit") { break; } But it still dint help.Hello Im trying to execute commands on server side. Here is my server based on other example from forum: [...]You are comparing whole buffer to "exit"
Sep 28 2015
On Monday 28 September 2015 11:59, holo wrote:I changed my condition to: if(to!string(buffer[0..received]) == "exit") { break; } But it still dint help.The client probably sends a newline; i.e. buffer[0 .. received] is "exit\n".
Sep 28 2015
On Monday 28 September 2015 12:40, anonymous wrote:The client probably sends a newline; i.e. buffer[0 .. received] is "exit\n".Or more likely it's "exit\r\n".
Sep 28 2015
On Monday, 28 September 2015 at 10:52:07 UTC, anonymous wrote:On Monday 28 September 2015 12:40, anonymous wrote:I changed condition to: if(to!string(buffer[0..received]) == "exit\n") { break; } and now it is working. Thank you all for help.The client probably sends a newline; i.e. buffer[0 .. received] is "exit\n".Or more likely it's "exit\r\n".
Sep 28 2015
On Monday, 28 September 2015 at 11:44:32 UTC, holo wrote:if(to!string(buffer[0..received]) == "exit\n")You shouldn't need that to!string by the way. I believe that will work just comparing the buffer directly. Converting to string is more important when you are storing a copy than just comparing it.
Sep 28 2015
On Monday, 28 September 2015 at 13:01:25 UTC, Adam D. Ruppe wrote:On Monday, 28 September 2015 at 11:44:32 UTC, holo wrote:Yep it it like you wrote. Thank you for advice.if(to!string(buffer[0..received]) == "exit\n")You shouldn't need that to!string by the way. I believe that will work just comparing the buffer directly. Converting to string is more important when you are storing a copy than just comparing it.
Sep 28 2015