Modded Socket.io

1
  • 30 favourites

Index

Attached Files

The following files have been attached to this tutorial:

.capx

socketioexample.capx

Download now 78.09 KB
.zip

socket-io-mod-johnnysheffield.zip

Download now 355.61 KB

Stats

11,615 visits, 29,309 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Update notes:

I DO NOT RECOMMEND using Socket.IO anymore, you should use the official multiplayer plugin.

I updated the Capx you are no longer needing the combobox & listbox plugin.

Rewrote a few comments to be better understandable.

Introduction

Firstly what this tutorial will cover, and what it wont cover:

It´s going to teach you how to setup your Socket.io Server.

It´s Going to teach you how to write your own Socket.io server in Javascript.

It´s not going to do the work for you.

What you need (Windows)

You´ll need a Windows PC (obviously)

Construct 2:

Node.JS: http://nodejs.org/download/

Eclipse IDE: http://www.eclipse.org/downloads/

Socket.IO plugin from Johnny Sheffield: It is in the download section to the left!

Setup everything

Setup Node.JS

First of all, download it, and install it. I hope I don´t need to cover how to install a normal program properly.

Then, open up CMD with Admin rights, and type in(example): cd c:\Nodejs

you can fill in at C:\Nodejs, with any path you want.

Then you need to type in: npm install socket.io

Wait a moment, because it will download socket.io and install it.

Now you succesfully installed Node.js and Socket.io!

Socket.IO

For scripting the server side, you´re going to need a Javascript IDE.

That stands for Integrated Development Enviorement.

You can use Eclipse for example, but i am going to use Adobe Dreamveawer.

But if you don´t want to install any unknown you can use the Editor, it´s integrated in EVERY windows pc.

Editor

Simply start the program, and then you can start coding. But when you´re saving it then your going on File → Save As → Filename: app.js → Filetype: All Files → Save.

Dreamveawer

Start the program, go on File → New... → Blank Page → Page Type: Javascript → Create.

Now when your going to save it, simply press save, and in filename type in thefilenameyouwant.js

That is how you´re doing it.

Javascript and Socket.IO

Javascript

No, you´re not going to learn the whole javascipt language, you can if you want to.

But i am only going to cover the important parts of it.

Variables

Variables can be numbers and strings.

You just need to say: yourvariablename = 0;

or yourvariablename = “String”;

or if you want to keep it empty in the beginning just say: yourvariablename;

The important thing in Javascript is you need to set a ; in the most endings of the line.

1: Yourvariablename = 0

2: Yourvariablename = 0;

1 is wrong, don´t do it like that, 2 is the right way to do it.

Functions

sockets.on('yourfunctionname', function (data) {

socket.dosomethinghere; });

understood?

Sockets.on defines that it is a socket function.

“youfunctionname” is, your function name, you can take “enemyxy” or whatever you want.

function(data) defines what variables you want to include in that function.

You could also say function(x,y) the , split the variables, so x is a variable and y is a variable.

Socket.dosomethinghere is where you are going to put you socket logic.

}); is needed to end a function, that describes where the function ends. { describes where it begins.

You probably saw the: socket.dosomethinghere; }); there were two ; its used to describe the end of a line, that means you could put 3 lines into one line, but that looks awful and is called bad-coding.

That is what you would need on javascript to make a server.

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!