Thread overview
How to use listener.d example?
Aug 31, 2018
Marcin
Aug 31, 2018
Neia Neutuladh
Sep 04, 2018
Marcin
Sep 04, 2018
rikki cattermole
Sep 04, 2018
Marcin
Sep 04, 2018
rikki cattermole
Sep 04, 2018
Marcin
Sep 04, 2018
Marcin
Sep 07, 2018
Marcin
Sep 11, 2018
Marcin
August 31, 2018
https://github.com/dlang/dmd/blob/master/samples/listener.d

Can some one add more comment to that example?

I need to make code that connects to local application, very similar to this.

Assumptions:
1. Create an application that listens to arguments.
2. Create an application that will send arguments to the application mentioned above.
3. The application will return the sine (argument) to the client.
4. All communication must be realized via console.

input:
1

1,2,3

4 5

44

Output:
"a =" 1 "sin (a) =" 0.84147

"a =" 1 "sin (a) =" 0.84147
"a =" 2 "sin (a) =" 0.9092
"a =" 3 "sin (a) =" 0.14112

"a =" 4 "sin (a) =" -0.756
"a =" 5 "sin (a) =" 0.9589

"a =" 44 "sin (a) =" 0.0177

Can some one help me write a server and client app?
I will use it to create more complicated application.




August 31, 2018
On Friday, 31 August 2018 at 07:38:54 UTC, Marcin wrote:
> https://github.com/dlang/dmd/blob/master/samples/listener.d
>
> Can some one add more comment to that example?
>
> I need to make code that connects to local application, very similar to this.
>
> Assumptions:
> 1. Create an application that listens to arguments.
> 2. Create an application that will send arguments to the application mentioned above.
> 3. The application will return the sine (argument) to the client.
> 4. All communication must be realized via console.

Another, more structured way to do this is with an RPC framework like Apache Thrift. With Thrift, you'd write an interface description:

---
namespace d math.api
service Sine
{
  double sine(1: double value);
}
---

In your application, you'd have something like:

---
import vibe.d;
import vibethrift;
import math.api.Sine;

class SineImpl : Sine
{
  double sine(double value)
  {
    static import std.math;
    return std.math.sin(value);
  }
}
void main()
{
  serve!Sine(new SineImpl, "0.0.0.0", 5555);
  return runApplication();
}
---

Then you use the corresponding Thrift client to make requests against it.

You could also do this with Vibe and REST:

---
import vibe.d;
class Sine
{
  @path("/sine")
  string getSine(double value)
  {
    static import std.math;
    import std.conv : to;
    return std.math.sin(value).to!string;
  }
}
void main()
{
  auto settings = new HTTPServerSettings;
  settings.port = 5555;
  auto router = new URLRouter;
  router.registerWebInterface(new Sine);
  listenHTTP(settings, router);
  runApplication();
}
---

And then you can point your browser at http://localhost:5555/sine?value=1.5 and get back 0.997495. You can similarly use std.net.curl to make the request.

But let's say you want to do everything yourself.

That script is the server. Line 55 is the thing that handles the input. You need to put your code there.

The remote application might send input in multiple packets. That means you have to collect input somewhere and figure out where the end is. You can either pass a length as the first part (usually a 4-byte value in network byte order), or require a special character to terminate the commend (I recommend the ASCII Record Separator character, U+001E, or the like), or know enough about your input to figure out where it ends anyway.

Once you get the end of your input, you send it off somewhere to parse and process. It's up to you how you want to send numbers across. When you're done, you need to convert the output numbers back to bytes somehow and send them back with socket.send(), and then you close the connection.

Once you've got that working, you need to write a client that does pretty much the same thing, but Socket.connect instead of the bind/listen/accept business, and you can just use Socket.read for the response rather than dealing with a SocketSet.
September 04, 2018
On Friday, 31 August 2018 at 07:38:54 UTC, Marcin wrote:
> https://github.com/dlang/dmd/blob/master/samples/listener.d


Im using Notepad++ as my IDE cuz i dont have administrator privileges on PC
To import modules i use -I option
cmd /k  cd C:\D\dtwo\windows\bin\ & C:\D\dtwo\windows\bin\dmd.exe -I="$(CURRENT_DIRECTORY)" "$(FULL_CURRENT_PATH)" & C:\D\dtwo\windows\bin\$(NAME_PART).exe

C:\Users\wjelki\Desktop\d\aplikacja.d(2): Error: module `server` is in file 'vibe\http\server.d' which cannot be read
import path[0] = C:\Users\wjelki\Desktop\d\vibe.d\core
import path[1] = .\..\..\src\phobos
import path[2] = .\..\..\src\druntime\import

How to import other modules than Phobos?


September 04, 2018
On 04/09/2018 10:57 PM, Marcin wrote:
> On Friday, 31 August 2018 at 07:38:54 UTC, Marcin wrote:
>> https://github.com/dlang/dmd/blob/master/samples/listener.d
> 
> 
> Im using Notepad++ as my IDE cuz i dont have administrator privileges on PC

Coedit is a good option since it is a simple unzip and ready to go. Although less than ugh "normal" but still a good option when nothing else decent exists.

https://github.com/BBasile/Coedit

> To import modules i use -I option
> cmd /k  cd C:\D\dtwo\windows\bin\ & C:\D\dtwo\windows\bin\dmd.exe -I="$(CURRENT_DIRECTORY)" "$(FULL_CURRENT_PATH)" & C:\D\dtwo\windows\bin\$(NAME_PART).exe

-I is only for directories and the modules contained must be already compiled and ready to be linked in.

> C:\Users\wjelki\Desktop\d\aplikacja.d(2): Error: module `server` is in file 'vibe\http\server.d' which cannot be read
> import path[0] = C:\Users\wjelki\Desktop\d\vibe.d\core
> import path[1] = .\..\..\src\phobos
> import path[2] = .\..\..\src\druntime\import
> 
> How to import other modules than Phobos?

For vibe.d use the build manager dub and yes dmd comes with it already.

But the general way to do it straight is:

dmd -of mylib.lib -lib a/filea.d a/fileb.d
dmd -of myprog.exe mylib.lib b/filec.d -I a

Of course that is off the top of my head and I only ever use dub so... take that with a grain of salt.
September 04, 2018
""
Am i doing it right?

I've unpacked vibe.d-master to my "C:\D\dtwo\src"
commands in cmd:

cd C:\D\dtwo\windows\bin\
echo "vibe.d-master is a folder"
dmd -lib C:\D\dtwo\src\vibe.d-master\core\vibe\appmain.d C:\D\dtwo\src\vibe.d-master\http\vibe\http\server.d


no wai, Ill just paste the vibe.d-master to my code location and add more arguments.

dub fetch vibe-d
downloaded something
dub run vibe-d
runs something
dub test vibe-d

vibe-d:redis 0.8.4: building configuration "library"...
vibe-d:web 0.8.4: building configuration "library"...
vibe-d 0.8.4: building configuration "vibe-d-test-vibe-core"...
Linking...
Error: linker exited with status 1
C:\D\dtwo\windows\bin\dmd.exe failed with exit code 1.

still don't work



I love programming... after 37 h of tryin to force run compiler.


September 05, 2018
On 05/09/2018 12:10 AM, Marcin wrote:
> ""
> Am i doing it right?
> 
> I've unpacked vibe.d-master to my "C:\D\dtwo\src"
> commands in cmd:
> 
> cd C:\D\dtwo\windows\bin\
> echo "vibe.d-master is a folder"
> dmd -lib C:\D\dtwo\src\vibe.d-master\core\vibe\appmain.d C:\D\dtwo\src\vibe.d-master\http\vibe\http\server.d
> 
> 
> no wai, Ill just paste the vibe.d-master to my code location and add more arguments.
> 
> dub fetch vibe-d
> downloaded something
> dub run vibe-d
> runs something
> dub test vibe-d
> 
> vibe-d:redis 0.8.4: building configuration "library"...
> vibe-d:web 0.8.4: building configuration "library"...
> vibe-d 0.8.4: building configuration "vibe-d-test-vibe-core"...
> Linking...
> Error: linker exited with status 1
> C:\D\dtwo\windows\bin\dmd.exe failed with exit code 1.
> 
> still don't work
> 
> 
> 
> I love programming... after 37 h of tryin to force run compiler.

You didn't need to download or manually fetch vibe-d yourself (it won't work this way FYI).
Just make sure dmd (windows/bin directory) is on your PATH variable, and you're good to go for the below example.

$ cd c:/projects/test_vibed
$ dub init
json
someprojectname
my description
Marcin
proprietary
Copyright 2018
vibe-d
\n
$ dub run
September 04, 2018
https://drive.google.com/open?id=1hC5SZ3VWX0iQoUO7KN0S-743x6FG9ER5

I give up

Cant compile this vibe-d

Ill get back to phobos

September 04, 2018
https://drive.google.com/open?id=1Qo6BYIZjaoxL_Z0TS9-vAN4ZgbTepkcR

I've reinstalled in other location and rewrite whole example.
I still get optlink error http://www.digitalmars.com/ctg/optlink.html
September 07, 2018
I get it working in linux environment.

I don't know why vibe-d get linker errors on win10.
September 11, 2018
On Friday, 7 September 2018 at 17:00:21 UTC, Marcin wrote:
> I get it working in linux environment.
>
> I don't know why vibe-d get linker errors on win10.

And I get it to work on windos
dub --build=release