简体   繁体   中英

How to communicate between d server and javascript

I'm new to socket programming. I studied the Mango from http://www.dsource.org/projects/mango . It looks like a good client/server communication if I'm building my client and server as D application. But what if the client is a browser with javascript?

How do I receive a struct from my D server? Any resource or examples that I can find? Most of the things I founds are socket.io or other similar things.

Thanks.

You might be better off using vibe.d for your web server. vibe.d is the currently the most popular D web server library, largely because of its completeness and efficiency.

For communicating between D and JavaScript, you probably want to use asychronous requests from the browser, which are executed from the client browser at any given time, and the server responds to. JSON would be a good format for you to communicate data with, and vibe.d offers some functionality for creating JSON data and HTTP responses with JSON data. jQuery has some functions for making creating asynchronous requests with JavaScript and JSON easy.

So in summary.

  1. Write a request handling function (with vibe.d if you use that library), which returns some JSON data, possibly accepting some request data. (Query string or POST data.)
  2. Write some JavaScript code which makes the request to the webserver, and does something meaningful with the response.

Additionally, if you are looking to push updates from your web server to your client application, vibe.d also offers some WebSocket functionality, for socket connections.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM