node. JS Server for Unity multiplayer game development

Source: Internet
Author: User
Tags dedicated server

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.