Node.js + Google Protocol Buffer + Unity 1차 코드
Programming/Mobile Server 2014. 10. 8. 07:35 |Node.js JavaScript 코드
이런식으로 작업을 해도 문제 없을 것 같네요.
// 웹서버 var Express = require('express'); var app = Express(); //protobuf var fs = require('fs'); var Schema = require('protobuf').Schema; // protobuf file 읽어 오기 var schema = new Schema(fs.readFileSync('GameMessagePacket.desc')); app.get('/GameServer/:id', function (request1, response) { var Msg = schema['Message.Login']; var Test = Msg.serialize({id : 'hoobboong', password : 'qwer1234'}); console.log('proto.length:', Test.length); response.send(Test); }); app.listen(3000);유니티 C# 코드
using UnityEngine; using System.Collections; using System.IO; public class NodeJSConnector : MonoBehaviour { // Use this for initialization void Start () { download(); } // Update is called once per frame void Update () { } private void download() { StartCoroutine(work()); } private IEnumerator work() { WWW www = new WWW("http://127.0.0.1:3000/GameServer/hoobboong"); yield return www; using (MemoryStream MemStream = new MemoryStream(www.bytes)) { Message.Login LoginMsg = ProtoBuf.Serializer.Deserialize우선 해당 소스 TEST 결과 이상 없이 데이터를 주고 받습니다. 좀 더 TEST 및 진행을 해봐야 하겠지만 현재까지는(MemStream); Debug.Log(LoginMsg.id); Debug.Log(LoginMsg.password); } } }
이런식으로 작업을 해도 문제 없을 것 같네요.
'Programming > Mobile Server' 카테고리의 다른 글
Node.js + Unity3D WebServer 연동 Test (0) | 2014.10.12 |
---|---|
Node.js + MySQL 연동 (0) | 2014.10.08 |