Friday, August 22, 2014

WebSocket Server & Mobile Client

Although i successfully using socket io to create a chatroom that able to let few computer to communicate but only computer that have node js are able to use the chatroom but that is not the connection i will like to have for my project. So me and tutor yee siang and jam who both are the professional in this industry sit down in the lab and try to figure out the possibility of fixing. Yee siang and jam did mention this is some like computer science level already so even them also need some research only can fix it. At that point i almost gave up and think i will fail my final year project but luckily Yee Siang are able to solve the problem. That night after the 2 hours meeting, Yee Siang tag in a facebook post, which is a tutorial he created to base on the problem i had . He said that when research on this area not body had share the solution. Just part and part, then he straight away combine the code and create a free source tutorial to share his tutorial.

So basically there are are few step need to beware of compare to our last time tutorial.

here is the link that send to me by my lecturer : http://tech.yeesiang.com/websocket-server-mobile-client/. if you are interested to this code can try to subscribe the blog.(yee siang i help you promote your blog. LOL )

You require to download Xampp, Node.js

To create the server you need to follow this few steps.

First, you need to have nodejs installed.
Save the code below into websock-server\index.js
Then, in your terminal/cmd, type npm install websocket@1.0.3 to install the nodejs websocket library.




Make sure your port 8080 is not occupied by other program as I am using port 8080 in this example.


Next, in your terminal/cmd, cd into the folder and type node index.js

var
http = require('http');
var server = http.createServer(function(request, response) {
    console.log((new Date()) + ' Received request for ' + request.url);
    response.writeHead(404);
    response.end();
});
server.listen(8080, function() {
    console.log((new Date()) + ' Server is listening on port 8080');
});
wsServer = new WebSocketServer({
    httpServer: server,
    // You should not use autoAcceptConnections for production
    // applications, as it defeats all standard cross-origin protection
    // facilities built into the protocol and the browser.  You should
    // *always* verify the connection's origin and decide whether or not
    // to accept it.
    autoAcceptConnections: false
});
function originIsAllowed(origin) {
  // put logic here to detect whether the specified origin is allowed.
  return true;
}
var connections = {};
var connectionIDCounter = 0;
    
wsServer.on('request', function(request) {
    if (!originIsAllowed(request.origin)) {
      // Make sure we only accept requests from an allowed origin
      request.reject();
      console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
      return;
    }
    //var connection = request.accept('kraken-protocol', request.origin);
    var connection = request.accept(null, request.origin);
    connection.id = connectionIDCounter ++;
    connections[connection.id] = connection;
    
   console.log((new Date()) + ' Connection ID ' + connection.id + ' accepted.');
    
    connection.on('message', function(message) {
        if (message.type === 'utf8') {
            console.log('Received Message: ' + message.utf8Data);
            //connection.sendUTF(message.utf8Data);
            broadcast(message.utf8Data)
        }
        else if (message.type === 'binary') {
            console.log('Received Binary Message of ' + message.binaryData.length + ' bytes');
            connection.sendBytes(message.binaryData);
        }
        
    });
    
    connection.on('close', function(reasonCode, description) {
        console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected. '+"Connection ID: " + connection.id);
        // Make sure to remove closed connections from the global pool
        delete connections[connection.id];
    });
});
// Broadcast to all open connections
function broadcast(data) {
    Object.keys(connections).forEach(function(key) {
        var connection = connections[key];
        if (connection.connected) {
            connection.send(data);
        }
    });
}
// Send a message to a connection by its connectionID
function sendToConnectionId(connectionID, data) {
    var connection = connections[connectionID];
    if (connection && connection.connected) {
        connection.send(data);
    }
}

Save then you will see this in your folder

This is able to use as server. Is user a output screen . Every time when people log in or out will have update. Then everything when people key in message it automatically update on the page.

After create the server we need to create the client files.

For the client part, the tutorial ask to going to create 2 interface, one for sending and receiving chat msg (index.htm), another for receiving chat msg only (logger.htm) which is the display.

You will need to change the Server IP in it into yours (ws://192.168.0.200:8080)

So now i can open the index.htm and type a msg, and it will appear on the space below the input box, as well as in logger.htm

I can even put index.htm into phonegap (need to provide option for user to enter the Server IP) and it can serve as a ‘controll’ while logger.htm can be modified to be a ‘receiver’ which also know as a "output".

Put the two files in the websock-client folder


index.htm source code
<head>
    <title>Node Based Echo</title>
    <script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="js/jquery.websocket-0.0.1.js" type="text/javascript"></script>
    <script src="js/jquery.json.min.js" type="text/javascript"></script>
</head>
<body>
    <script type="text/javascript">
        // sends a message to the websocket server
        function sendToServer() {
            ws.send('say', '{ messageTextA: ' + $('#echoText').val() + ' }');
            //ws.send('krakenmsgB', '{ messageTextB: ' + $('#echoText').val() + ' }');
        }
        // set-up web socket
        var ws = $.websocket("ws://192.168.0.200:8080/", {
            open: function () { },
            close: function () { alert('websocket has been closed'); },
            events: {
                say: function (e) { $('#returnText').append(e.data + "<br/>"); },
            }
        });
    </script>
    <div>
        <div style="float: left; clear: left; padding-top: 2px;">
            Your text:
        </div>
        <div style="float: left; padding-left: 20px;">
            <input type="text" id="echoText" style="width: 150px;" required />
        </div>
        <div style="clear: left;">
            <input type="button" onclick="javascript:sendToServer();" value="Send" />
        </div>
        <div id="returnText" style="clear: left; height: 200px; padding-top: 30px;">
        </div>
    </div>
</body>
</html>

Then logger.htm source code

<html lang="en"> <head> <title>Logger</title> <script src="js/jquery-1.6.2.min.js" type="text/javascript"></script> <script src="js/jquery.websocket-0.0.1.js" type="text/javascript"></script> <script src="js/jquery.json.min.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> // set-up web socket var ws = $.websocket("ws://localhost:8080/", { open: function () { }, close: function () { alert('websocket has been closed'); }, events: { say: function (e) { $('#returnText').append(e.data + "<br/>"); }, } }); </script> <div> <div id="returnText" style="clear: left; height: 200px; padding-top: 30px;"> </div> </div> </body> </html>

To try it  copy the websock-client files into xampp htdocs first so that phone are able to connect to the folder to internet database.


Start xampp first before launch in browser. and also terminal as well .

So this will be how it will look like 







Tuesday, August 19, 2014

Creating wireframe , and interface mock up

Due to spending too much time on solving coding and programming part i was lack of time on creating the content. I need to think and play save . base on the game that i have i start go back all the google experimental game that are created to evaluated and scan on how they design their game interface. Most of the graphic are is vector format. The interface are clean and nice also easy to understand.  Base on this few point i quickly sketch out a few idea then start to create my wireframe and interface mock up 

 below is some of my sketch, wireframe and my interface mock up.

Sketches and notes







Wireframes








Interface mock up



Thursday, August 14, 2014

Create Flowchat, User Senario, and Equipments

The reason why do i create this few thing so early is because of this can help me check on my idea and concept and user experience.

Both of my tutor didn't ask me to create these things. Yi Wei is focus on user experience, idea and concept. Yee Siang is able to help me on coding. I was motivated to create this when i was waiting for Jeremy to finish the consultation with Jazmi and i overhear the word user scenario which make remind of the project we did in TWP is level 5 which help us to understand better on the artefact that we are creating. And create flowchart and scenario also able to how to create a step by step tutorial to the participant.

Flowchart




Floorplan and equipment 
The measurement of projection distance to help me calculate my floorplan and below are the equipment i will be using during the exhibition


Projector screen or back projection 

Panasonic PT-LB1EA 3LCD Projector (30.73cm x 6.86cm x 21.08cm)


Dell or mac desktop
Router

User Scenario
Game 1 (Pop the Bottle)


Game 2
Space Fighter



Similar project by Leo Burnett Interactive Outdoor Challenge (Industry Benchmark)

Interactive billboard by Leo Burnett

This was stunning to me as i saw this article and the date of articles. I was researching on some of my coding then suddenly when through some video that was share in my social media. I do notice on this campaign created by Mcdonald about the ice cream but i didn't look deeper into how the campaign was created and the few minutes of video i realised that the concept and idea are very similar to my ideas.
And the first thing come into my mind is that will my project be marked as plagiarism ? I was so afraid i texted my lecturer through social media about the news and he reply that it is ok. And he do say that the idea is not really original also due to it is created long time at oversea just that in malaysia is still new. And the project that done by Leo Burnett is by a team and i am creating it myself so it will very less percentage of marking as plagiarism. And ask me to continue my project.

This project had won two awards.

And this the video that i saw :



A big sigh after i saw these, maybe great mind think alike. And i am regret why didn't i come out the idea sooner. Hopefully this blog will mark a benchmark and reference for me to show that i am not plagiarising them.

Since there is a similar project that are found in malaysia. I am able to set it as one of the industry benchmark so that i am able to understand and improvise from existing sample.

After analysing this project the connection is similar which is using web connection to set data to the main server then transfer back to games, which we can say is using websocket to create interaction and make the phone as a controller. But this installation only able for one person at a time. Which did not fully utilize the power of websocket which allow multiple user. Maybe this is one of the experience they want to create. But they did utilise the power of gesture in mobile devices to give the user a very similar experience that they are really rotating the fan to make it spin. Which you will find in my installation.

As you can refer back to my previous blog that are talking about hybrid event, I did explain that by gamified the interactive installation; it is able to attract more crowds and giving them a feedback like rewards will motivate them to participate.

References:

http://www.marketingmagazine.com.my/index.php/categories/breaking-news/9993-leo-burnett-s-double-win-at-malaysia-s-first-interactive-outdoor-challenge

http://www.thestar.com.my/News/Community/2014/01/23/Interactive-billboard-to-shift-consumers-minds/

Wednesday, August 13, 2014

Weekly tutorial (6) with Yi Wei (Major issue that i face during my project)

During this last tutorial i realise i am abit back on schedules and lost in the direction i had been worry and testing too much on connection which make me forget what is my objective and selling point .

During the discussion with Sweii and Yi Wei. They list down something that i need figure it out to solve this major issue. If not my project will not be that interesting during the pitch. Because if the content is not there or special enough people will think that the phone is just controller. which a lot of thing can be replace it and save  a lot of time while doing it .

Yi Wei: Content may help to sell the project!!
Sweii: After testing on so many tutorial which one is the most suitable tool to apply to my idea. And i should decide on this earlier rather than now.

I do make my decision in the early stage but during the progress of learning and understand i do realised that there are some limitation. I will like to make the project to be perfect. But maybe i am negative people, i worry too much on time and my skillset and this had cause me to think so much and make myself limited to solve one thing at a time so that i proceed safely which is a big impact of causing me slow down in my progress.

Action: Stop on tutorial and start building on content and idea. Find more research to back the content up to make it even solid.

Yi Wei: For example user can access the artefact after connect to the router and participant at anyplace they want.

This give me a trigger point to come out my idea. when i am back i went back to SOI and see what i want to create at the starting of my project. And re-analysed everything tutorial that i had did and come out a conclusion what are thing that i need to focus on. Beside that i also list out what are the area i am able to complete for my final exhibition and base on that i need to decide the what i need to do.

After analysed i decide that i will creating a web instate of an application. And by using QR code or url to link to pages. The flowchart and user scenario is record in this blog.

As for create as an application, i will be include this idea into my pitch for future possibilities. to show that the possibilities of update of the technology of my project.

After than i come out the how my project should work and solve the problem that i state on my SOI.

A wider connection router connection able to bring crowd to event after connected to the free router wifi signal. When connect and connect to web browser the ads and promotion material will pop out to tell user that the event is happening so they come and join the event and make had a chance to win a prize.

Using mobile a best way to prevent for property lost and destroy. Beside that socket oi are able to connect with unlimited user. which make it useful when that are games that will be interest when there are plenty of players. And with the gesture that are available on the mobile devices, the way of interactive with the games will be more exciting like user are able to swiping, accelerometer,  pinch and scale to interact with the games.


  • It is able to promote the event to the user when connected to the browser as a promotion tool.
  • Increase participant and solve limited space problem.
  • Saving cost and budget by prevent logistic problem.
  • Create a new experience to the participants.
  • Using the closer gadget of people to create a simple, fun and memorable experience of interaction.


I very appreciate that Sweii and Yi Wei helping me on this stage, i am kind of lost during that time and Sweii say that use what i had try to see what is the most suitable solution for the situation now and apply it .

Thank you.