Client-Server Comments. How to start?

Hello everybody! I’m a total newbie with client-server apps and really hope you can give me some advice from where to start. I want to create something simple, like find a user in a list and send him a comment to his board. Is there any internal tools for doing this or what is the best way to realize it?

In a technical sense, a common way to do this is to send and receive JSON-formatted packets using HTTP.   The potential advantage to this is that you are simply using “web server” tools and techniques.

From a more-general design perspective, client-server generally involves one program making a request to another program and receiving a packet of data in response.   A common name for this approach is “RPC = Remote Procedure Call,” which is actually quite descriptive.   Your server might implement a call that, given a user-id and a message, attempts to post the message as a comment to the user’s board.   The server’s response will indicate whether the attempt succeeded, and, if not, why it did not.

“Find a user in a list” would involve the server sending you a list of users, after which your program must present the list and allow the user to select from it, for use in subsequent client requests.   The problems being (a) it could be a very large list, and (b) you may or may not wish to reveal a complete list of just who your users are.

1 Like

Maybe look into REST endpoints to get and post data to your server? Something like this probably doesn’t need a constant connection like a websocket and just calling urls on demand will probably suffice. JSON or XML are good text based formats that are widely used.

Thank you very much! Now I see it more clear.
Also what is best way to send/receive packets via OpenFL for cpp target?
I’ve found this thread - http://community.openfl.org/t/how-to-connect-to-a-server-using-openfl/7353
Is it will be a good choice to use such approach?

URLRequests are the usual way of sending and receiving data from servers in a single HTTP request using OpenFL. You will need to send POST variables to your server but the return GET format from the server is up to you.

Sockets can be used but might be a bit overkill for this solution. They are mainly used if a client and server need to be in constant communication.

Okay, pretty simple I think. So I’ve send the request with user id and a comment to server, but what if I want to get the status about that comment right back? Is there something like to add a listener, or I should send requests to server on timer while I didn’t get the right one?

You should be able to add a complete listener. When you POST, the server accepts your data and then sends a response. You can respond with any data you like so you can get your server to use the data and then return any status information about it in the same call.

That’s awesome, thank you!
Also is there any advice of how to code a server? Someone suggested me to make it using nodejs. Or maybe it is possible to create it with OpenFL?

To build own haxe tcp-server to run from console (or deamonized on dedicated computer),
its possible:

http://old.haxe.org/doc/neko/client_server
or with this greatful lib: https://github.com/MattTuttle/hxnet

But it will need some special code to implement simple http-protocol (recieve/send to Clients that use
URLRequests). May perl or python would be better for http-standaloneserver (more code-examples and oneliner out there to use ;).

Good solution today is using websockets together with node.js serverside, because its easy to host in “clouds” to handle massive requests (like http://peerjs.com/ does with js-only).

I did some lib for my own, but thats not tested in all kinds yet (simple chatserver there work like this way:
https://github.com/maitag/peote-net/blob/master/samples/chat/Source/ServerChannel.hx#L52) :slight_smile:

Thank you for that knowledge! As I understood, I need to choose between urlRequests and Sockets depending on own needs. If it’s something light, then better solution would be requests, otherwise sockets.

Hey, I’m currently working on a node server using the TCP-protocol for a real-time game(not ideal perhaps…). If you have any specific questions regarding node and openfl socket communication, let me know!

Thank you Tej! I see nodejs is a really choice to make your own server.