2

Hi I was wondering how one would go about setting up a delphi server that can interact with a javascript client. I am developing a game with this tool : www.scirra.com

It is called construct 2 and it uses javascript. It has a plugin to use socket.io and websockets so either one would be great.

So basicly I want to develop a delphi server that would receive messages from the one javascript client and broadcast it to the other javascript client. If the user wanted to host a game he would run the delphi application and then join the game and wait for other players to join.

To sum up; (A) Is it possible to use websockets in delphi to communicate with javascript. (B) if so would someone please make a simple demo.

Thanks for your time

mjn
  • 36,362
  • 28
  • 176
  • 378
Kobus Vdwalt
  • 347
  • 1
  • 7
  • 20

1 Answers1

3

There are some WebSocket client and server implementations available (see WebSocket server implementations for Delphi).

By design, client-side JavaScript (in the browser) can use the WebSocket protocol to communicate with the server. The Delphi WebSocket server implementations then can handle the requests and push data back to the client just like any other WebSocket server library. However, I do not know anything about the code quality or Delphi version compatibility of all these libraries so some additional research is required.

Regarding the Demo: most libraries surely include some demo HTML with JavaScript / WebSocket communication. Simply download it and open it in your favorite text editor ;)

p.s. as I can see socket.io not only supports WebSocket but also long polling so basically you can use any HTTP server library for Delphi to write the server side logic. See:

Community
  • 1
  • 1
mjn
  • 36,362
  • 28
  • 176
  • 378
  • Thanks for the info ill ckeck it out when I'm at my home computer – Kobus Vdwalt May 11 '13 at 10:40
  • I am having trouble with all the solutions mentioned in that thread and i was wondering could you not have a websocket server that uses indy? – Kobus Vdwalt May 12 '13 at 10:33
  • @KobusVdwalt that thread also linked to http://stackoverflow.com/a/13193258/80901 which points to a client and server WebSocket implementation based on Indy – mjn May 12 '13 at 11:02
  • That code is disconected.(http://asmprofiler.googlecode.com/svn/trunk/-Other-/IndyWebsocketDemo/) i would like to just download a project that works. If you would be so kind as to just make a demo it would be great – Kobus Vdwalt May 12 '13 at 11:12