Sun Guangdong 2016.5.4
How to use a dedicated server-driven node. js Create our own multiplayer game. This will build on WebSocket's real-time response to multiplayer games. Write your own logic.
First, Search the Assetstore for the Web Socket 0> See Unity 's official plugin '
https://www.assetstore.unity3d.com/cn/#!/content/38367
then introduce an Open Source Library Socket IO
https://www.assetstore.unity3d.com/en/#!/content/21721
There's a piece of paper that compares these two.
https://gist.github.com/zeusdeux/5491cff541fb4ac4c142
and then import it into the project. Socketio
Download Development Tools Brackets
in the project's Asset folder Sibling New directory server , and then use Brackets to Open this folder.
We search Socket IO , The entry address is: http://socket.io/get-started/chat/
http://socket.io/docs/# Documents can view various APIs.
came to this Server folder into CMD , and then enter
and then it appeared in the project.
also to install :
Client Connection Server
Require () asynchronously loads the Socket.io and then executes a callback function to construct a iovar IO = require (' Socket.io ') (Process.env.PORT | | 3000);// Output a Logconsole.log (' server started ');
also in the console boot server , IP: localhost, port:3000 input :
Node Add this code:
Io.on (' Connection ', function (socket) { Console.log (' client is connected ');})
UnityCreate a newMainscene, Create a new object namingNetWork and then add the script socketiocomponent. CS Then Set The port number is in our code the.
then we CMD Start Node server, and then in the play model Unity Editor. you see the output:
??
node. JS Server for Unity multiplayer game development