How do I make a word-cloud a real time?

Get help using Construct 2

Post » Thu Jul 14, 2016 9:11 am

Hi,

How do I make a WORD CLOUD a real time to other users?
Here is my sample created using Construct 2.
https://dl.dropboxusercontent.com/u/519 ... index.html

When I input a word, it will fall down.
If other user input a WORD, I can also see the word in real time and save all in an xml or database for future viewing.

I'm thinking of Node.js but I my knowledge is limited.

Thanks for any information.
B
23
S
6
G
3
Posts: 39
Reputation: 4,759

Post » Fri Jul 15, 2016 2:15 pm

If you have your heart set on Node.js:
https://expressjs.com/en/guide/database ... ation.html
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Sat Jul 16, 2016 2:37 pm

Hi Gumshoe2099,

I tried Nodejs but I am not that good.
Here's my server code below.
My problem is that, when I send data to server, I can't get back the data back but it will display in console.
Any idea?

var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});
B
23
S
6
G
3
Posts: 39
Reputation: 4,759


Post » Sat Jul 16, 2016 4:13 pm

morex wrote:var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});

The one main problem that I see right off is that you rolled your onmessage method into your onconnection method.

Those two need to be separate functions, like:
Code: Select all
var WebSocketServer = require('ws').Server, wss = new WebSocketServer({port: 8080});

wss.on('connection', function(ws) {
        ws.send('Connected.');
 });

ws.on('message', function(message) {
        console.log('received: %s', message);
            ws.send('Message received.');
    });


You also need to make sure that you have the "Access-Control-Allow-Origin" header set to '*' because Construct is very particular about security, and your websockets will not work if that header is not set on the server side.

See this example for more info: http://usualcarrot.com/nodejs-and-webso ... t-tutorial

You can see the compartmentalization in my Java WebSocket server code below:
Code: Select all
public GalaxyChatEndPoint(){
       mLog = new MessageLogManager(filePath, fLogger, SP);
    }
   
    /**
     * Callback hook for Connection open events. This method will be invoked when a
     * client requests for a WebSocket connection.
     * @param userSession the userSession which is opened.
     */
    @OnOpen
    public void onOpen(Session userSession){
       try{
          userSession.setMaxIdleTimeout(600000);//10 mins
           sessionKey = ((PrincipalWithSession) userSession.getUserPrincipal()).getSessionKey();
           gameSession = cache.get(sessionKey.getKey());
            connections.put(sessionKey, userSession);
            if(gameSession==null)
               broadcast("<p>gumshoe joined chat.</p>");
            else
               broadcast(String.format("<p>%s%s</p>", gameSession.getDisplayName()," joined chat."));
       }catch(Exception e){
          fLogger.error(Errors.err2String(e));
          try {
            connections.get(sessionKey).close();
            connections.remove(sessionKey);
         } catch (IOException e1){
             fLogger.error(Errors.err2String(e1));
         }
       }
    }
     
    /**
     * Callback hook for Connection close events. This method will be invoked when a
     * client closes a WebSocket connection.
     * @param userSession the userSession which is opened.
     */
    @OnClose
    public void onClose() {
       try{
          if(gameSession==null)
             broadcast("<p>gumshoe left chat.</p>");
          else
             broadcast(String.format("<p>%s%s</p>", gameSession.getDisplayName()," left chat."));
         connections.get(sessionKey).close();
         connections.remove(sessionKey);
       }catch(Exception e){
          fLogger.error(Errors.err2String(e));
          try {
            if(connections.get(sessionKey)!=null)connections.get(sessionKey).close();
            if(connections.get(sessionKey)!=null)connections.remove(sessionKey);
         } catch (IOException e1){
             fLogger.error(Errors.err2String(e1));
         }
       }
    }
     
    /**
     * Callback hook for Message Events. This method will be invoked when a client
     * sends a message.
     * @param message The text message
     * @param userSession The session of the client
     */
    @OnMessage
    public void onMessage(String messageJson) {
       try{
          Date now = new Date();
          String dateFmt = new SimpleDateFormat("EEE MMM HH:mm:ss z yyyy").format(now);
          Message message = Message.fromJson(messageJson, gameSession);
          globalMessageLog.put(currentMessageId.incrementAndGet(), message);
          if(message.getDestination().getDestType()==DestinationType.GALAXY)
             if(gameSession==null)
                broadcast(String.format(galaxyChatFramework, dateFmt, "gumshoe", message.getContent()));
             else
                broadcast(String.format(galaxyChatFramework, dateFmt, gameSession.getDisplayName(), message.getContent()));
          // this may need to be reworked...  perhaps to a raw message number system
          Date time1159pm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd").format(now) + " 23:59:58");
          
          if(now.after(time1159pm)){
             if(mLog.writeFile(globalMessageLog, now)){
                globalMessageLog.clear();
                currentMessageId.set(0);
             }
          }
       }catch(Exception e){
          fLogger.error(Errors.err2String(e));
         try {
            connections.get(sessionKey).close();
            connections.remove(sessionKey);
         } catch (IOException e1){
             fLogger.error(Errors.err2String(e1));
         }
       }
    }
   
    private static void broadcast(String msg) throws Exception {
       for(Session client : connections.values()){
          synchronized (client) {
              if(client.isOpen()) client.getBasicRemote().sendText(msg);
          }
       }
    }
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Sat Jul 16, 2016 5:38 pm

Hi,

Sorry, Still I can't make it to work.
Here is the C2 file that I am currently working on.
https://dl.dropboxusercontent.com/u/519 ... dcloud.zip

What I want to achieve is when I input a word, it will also appear on the other browser and vice-versa.
B
23
S
6
G
3
Posts: 39
Reputation: 4,759

Post » Sat Jul 16, 2016 5:42 pm

I suspect the problem is on your server code, not your Construct2 code. Did you look at that example?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Wed Apr 26, 2017 5:09 pm

hello,

any chance for a reupload of your wordcloud demo?
i stumbled over this info here: https://mathematica.stackexchange.com/q ... word-cloud
https://mathematica.stackexchange.com/q ... ord-clouds
B
80
S
29
G
113
Posts: 195
Reputation: 62,535


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne, Google [Bot] and 5 guests