Node.js + Google Protocol Buffer + Express + MySQL (Server 구성)

Unity3D Coroutine + WWW (Client 구성)

0.1초 마다 WebServer에 요청 시도 하는 Client 20개로 TEST 진행

컴퓨터 사항 : I-5 2500K 3.30GHz + RAM 8GB + SSD 구성

'Programming > Mobile Server' 카테고리의 다른 글

Node.js + MySQL 연동  (0) 2014.10.08
Node.js + Google Protocol Buffer + Unity 1차 코드  (0) 2014.10.08
Posted by Habentius
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 웹서버
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'));
// MySQL
var mysql = require('mysql');
var DBConnectionPool = mysql.createPool(
{
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'qwer1234',
    database: 'game',
    connectionLimit: 100,
    waitForConnections: true,
    multipleStatements: true
});
// all environments
app.use(express.logger('dev'));
// development only
if ('development' == app.get('env')) {
    app.use(express.errorHandler());
}
// 로그인 SP 호출
app.get('/Login/:id/:password'function (request1, response) {  
    var Data = [request1.params.id, request1.params.password]
    
    var queryString = "CALL sp_LoginProcedure(?, ?, @result); SELECT @result AS Result;"
    
    DBConnectionPool.getConnection(function (err, connection) {
        var query = connection.query(queryString, Data, function (err, results) {
            if (err) {
                connection.release();
                console.error(err);
                throw err;
            }
            
            var Msg = schema['Message.LoginResult'];
            var ResultMsg = Msg.serialize({ result: results[1][0].Result });
            response.send(ResultMsg);
            
            console.log(results);
            connection.release();
        });
    });
});
// 회원가입 SP 호출
app.get('/Signup/:id/:password'function (request1, response) {
    var UserID = request1.params.id
    var UserPW = request1.params.password
    
    var queryString = "CALL sp_SignupProcedure('" + UserID + "','" + UserPW + "', @result); SELECT @result AS Result;"
    
    DBConnectionPool.getConnection(function (err, connection) {
        var query = connection.query(queryString, function (err, results) {
            if (err) {
                connection.release();
                console.error(err);
                throw err;
            }
            
            var Msg = schema['Message.SignupResult'];
            var ResultMsg = Msg.serialize({ result: results[1][0].Result });
            response.send(ResultMsg);
            
            connection.release();
        });
    });
});
// 캐릭터 정보 얻어 오기
app.get('/CharacterInfo/:userkey'function (request1, response) {
    
    var UserKey = request1.params.userkey
    
    var queryString = "CALL sp_GetCharacterInfo_procedure('" + UserKey + "');"
    
    DBConnectionPool.getConnection(function (err, connection) {
        var query = connection.query(queryString, function (err, results) {
            if (err) {
                connection.release();
                console.error(err);
                throw err;
            }
            
            var Msg = schema['Message.CharacterInfoResult'];
            
            var Data = {
                money: results[0][0].user_money,
                level: results[0][0].user_level,
                exp: results[0][0].user_exp,
                maxexp: results[0][0].user_maxexp,
                attackvalue: results[0][0].user_attackvalue,
                defencevalue: results[0][0].user_defencevalue,
                critical: results[0][0].user_critical,
                maxhp: results[0][0].user_maxhp,
                maxmp: results[0][0].user_maxmp,
                groupname: results[0][0].user_groupname,
                grade: results[0][0].user_class
            };
            
            //console.log(Data);
            var ResultMsg = Msg.serialize(Data);
            
            console.log('Data.Length:', ResultMsg.length);
            response.send(ResultMsg);
            
            connection.release();
        });
    });
});
app.listen(3000);

cs


Posted by Habentius
:
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(MemStream);
            Debug.Log(LoginMsg.id);
            Debug.Log(LoginMsg.password);
        }
    }
}
우선 해당 소스 TEST 결과 이상 없이 데이터를 주고 받습니다. 좀 더 TEST 및 진행을 해봐야 하겠지만 현재까지는
이런식으로 작업을 해도 문제 없을 것 같네요.

'Programming > Mobile Server' 카테고리의 다른 글

Node.js + Unity3D WebServer 연동 Test  (0) 2014.10.12
Node.js + MySQL 연동  (0) 2014.10.08
Posted by Habentius
:
#include "fstream"

std::ofstream		fOutDataFile;	// 파일 생성 및 입력
std::ifstream		fInDataFile;	// 파일 읽어 오기

// 파일 생성
{
	// 바이너리 값을 입력 할 수 있도록 생성
	fOutDataFile.open( "DataFile.dat", std::ios_base::binary );

	if ( fOutDataFile.fail() )
	{
		return;
	}
}

// INT형 쓰기
{
	int		nValue;

	fOutDataFile.write( (const char*)nValue, sizeof(nValue) );
}

// String형 쓰기
{
	std::string strValue = "MonsterName";
	int			nSize	 = strValue.size();

	fOutDataFile.write( (const char*)nSize, sizeof(nSize) );
	fOutDataFile.write( strValue.c_str(), nSize );
}

// 파일 읽기
{
	int nOpenMode = std::ios_base::in || std::ios_base::binary;

	fInDataFile.open( "DataFile.dat", nOpenMode );

	if ( fInDataFile.fail() )
	{
		return;
	}
}

// INT형 읽기
{
	int		Value = 0;

	fInDataFile.read( (char*)&Value, sizeof(Value) );
}

// String형 읽기
{
	int			nSize		= 0;	
	char		Buf[512]	= "";
	std::string	strValue	= "";

	fInDataFile.read( (char*)&nSize, sizeof(nSize) );
	fInDataFile.read( Buf, nSize);

	strValue = Buf;
}

'Programming > C/C++' 카테고리의 다른 글

숫자 타입 String에 담기  (0) 2012.11.05
스마트 포인터 사용법 정리  (0) 2012.11.05
Map 사용 방법 정리  (0) 2012.11.05
Posted by Habentius
:
#include "sstream"

{
	std::string			strString;
	std::ostringstream	ost;
	int					nNumber = 100;

	ost.str("");
	ost << nNumber;

	strString += ost.str();
}

'Programming > C/C++' 카테고리의 다른 글

파일 입출력 사용법 정리  (0) 2012.11.05
스마트 포인터 사용법 정리  (0) 2012.11.05
Map 사용 방법 정리  (0) 2012.11.05
Posted by Habentius
:
CWinThread*		WinThread = NULL;

// 쓰레드로 처리할 루프
UINT __cdecl ThreadLoop(LPVOID pParam)
{
	BOOL *pbContinue = (BOOL *)pParam;

	while(*pbContinue)
	{
		Sleep(1);
	}

	return 0;
}

// 쓰레드 시작
WinThread = AfxBeginThread(ThreadLoop, this);

// 쓰레드 종료
DWORD nExitCode = NULL ;

GetExitCodeThread( WinThread->m_hThread, &nExitCode ) ;
TerminateThread( WinThread->m_hThread, nExitCode ) ;

'Programming > API' 카테고리의 다른 글

[API] Basic Window  (0) 2010.09.16
Posted by Habentius
:
#include "boost shared_ptr.hpp"

class CEntity
{
private:
	int	m_nEntityType;

public:
	void SetEntiyType(int a_nEntityType)	{ m_nEntityType = a_nEntityType; }
	int  GetEntiyType(void)					{ return m_nEntityType; }

public:
	CEntity(void) {}
	~CEntity(void) {}
};

{
	// 선언 및 동적 할당
	// 스마트 포인터의 경우 선언과 동시에 동적할당을 해 주어야 한다.
	boost::shared_ptr		spEntity(new CEntity);

	// 포인터 처럼 사용 하면 된다.
	spEntity->SetEntiyType( TY_MONSTER );
	int nEntityType		= spEntity->GetEntiyType();

	 // 포인터 얻어 오기
	CEntity* pentity	= spEntity.get();
}

'Programming > C/C++' 카테고리의 다른 글

파일 입출력 사용법 정리  (0) 2012.11.05
숫자 타입 String에 담기  (0) 2012.11.05
Map 사용 방법 정리  (0) 2012.11.05
Posted by Habentius
:
#include 

struct ObjectInfo
{
	int nX;
	int nY;
};

std::map	ObjectMapList;

//	Map 루프
{
	std::map::iterator iter	= ObjectMapList.begin();
	std::map::iterator end		= ObjectMapList.end();

	for ( /**/;	iter != end; ++iter )
	{
		if ( iter == ObjectMapList.end() )
		{
			continue;
		}

		std::string		objectname	= iter->first;
		ObjectInfo		objectinfo  = iter->second;
	}
}

// Map 검색
{
	std::map::iterator iter = ObjectMapList.find("Renderer");

	if ( iter == ObjectMapList.end() )
	{
		return NULL;
	}

	return iter->second;
}

// Map 삽입
{
	std::string		objectname;
	ObjectInfo		objectinfo;

	objectname	  = "Renderer";
	objectinfo.nX = 0;
	objectinfo.nY = 0;

	ObjectMapList.insert( std::pair( objectname, objectinfo ) );
}

// Map 삭제
ObjectMapList.clear();
 
{
    std::map::iterator iter = ObjectMapList.find("Renderer");
 
    if ( iter == ObjectMapList.end() )
    {
        return NULL;
    }
 
    ObjectMapList.erase( iter );
}


'Programming > C/C++' 카테고리의 다른 글

파일 입출력 사용법 정리  (0) 2012.11.05
숫자 타입 String에 담기  (0) 2012.11.05
스마트 포인터 사용법 정리  (0) 2012.11.05
Posted by Habentius
:



개발환경 : Visual Studio 2008, DirectX SDK, C/C++
XML 캐릭터 애니메이션, 평면그림자, 스프라이트를 이용하여 2D 이미지 처리

3D 턴제용 카드 게임 - 이누야샤 플래시 게임을 3D로 개발
Posted by Habentius
:

1. Google AI Challenge의 로그인 후 오른쪽 중간의 Upload Your Code가 있다.


2. Starter Packages에서 받은 그대로 (AI Source만 변경 후 나머지 File은 그대로 존재) Zip File로 하여 Choose Your Zip File에 찾아보기를 이용하여 Zip File을 올리면 된다


3. Upload를 완료를 하면 아래와 같은 글이 출력 된다

'Programming > AI Challenge' 카테고리의 다른 글

JDK 설치 및 설정 방법  (0) 2010.09.28
Google AI Challenge 대해서  (0) 2010.09.27
Posted by Habentius
: