--- /dev/null
+Debug/
+Release/
+ipch
+*.suo
+*.dll
+*.lib
+*.sdf
+*.opensdf
+*.filters
+*.user
+
--- /dev/null
+#include "CConnection.h"
+
+
+////////////////////////////////////////////////////////////////////////////////
+// \83R\83\93\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CConnection::CConnection()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83f\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CConnection::~CConnection()
+{
+ m_Socket.uninitialize();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// initialize
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::initialize()
+{
+ m_Socket.initialize();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// open port
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::openPort()
+{
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// close port
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::closePort()
+{
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// accept
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::accept()
+{
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// connection
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::connection()
+{
+ m_Socket.connection();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// disconnection
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::disconnection()
+{
+ // \91\97\90M\92\86\8e~
+ m_Socket.shutdown(0);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83f\81[\83^\82ð\91\97\90M\82·\82é
+// \8aÖ\90\94\8cÄ\82Ñ\8fo\82µ\8e\9e\82É\91¦\91\97\90M\82ð\8ds\82¤
+// \83o\83b\83t\83@\82ð\97\98\97p\82µ\82Ä\8bó\82¢\82½\8e\9e\8aÔ\82É\91\97\90M\82µ\82½\82Ù\82¤\82ª\82æ\82¢\82©\82Ç\82¤\82©\82Í\8cã\82Å\8c\9f\8fØ\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::setSendData(const CommunicationBuffer* in_pCommunicationBuffer)
+{
+ // \96{\97\88\82Í\88ø\90\94\82É\91\97\90M\82·\82é\83N\83\89\83C\83A\83\93\83g\8fî\95ñ\82ð\95t\89Á\82µ\82Ä\81A\91\97\90M\82·\82é\90æ\82²\82Æ\82ÌTcp\83N\83\89\83X\82ð\91I\91ð\82·\82é\81B
+ return m_Socket.send(in_pCommunicationBuffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8eó\90M\83f\81[\83^\82ð\8eæ\93¾\82·\82é
+// \8eó\90M\83f\81[\83^\82Í\83R\83}\83\93\83h\81A\89¹\90º\82È\82Ç\82·\82×\82Ä\82ð\8aÜ\82Þ
+////////////////////////////////////////////////////////////////////////////////
+bool CConnection::getReceiveData(CommunicationBuffer** out_ppCommunicationBuffer)
+{
+ // \96{\97\88\82Í\8eó\90M\8c³\83N\83\89\83C\83A\83\93\83g\82Ì\8fî\95ñ\82ð\95t\89Á\82µ\82Ä\81A\88ø\90\94\82Æ\82µ\82Ä\95Ô\82·
+ bool a_Result = m_Socket.receive(out_ppCommunicationBuffer);
+ return a_Result;
+}
+
--- /dev/null
+#ifndef INC_CConnection
+#define INC_CConnection
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "CSocket.h"
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+
+////////////////////////////////////////////////////////////////////////////////
+// CConnection
+// \92Ê\90M\91\8d\8d\87\8aÇ\97\9d
+// internetcity\97p\82Ì\92Ê\90M\97p
+// \83R\83}\83\93\83h\82È\82çTCP\81A\89¹\90º\82È\82çUDP\82ð\8eg\97p\82·\82é
+// \83T\81[\83o\81[\82Æ\83N\83\89\83C\83A\83\93\83g\82Å\8b¤\92Ê\82Å\8eg\97p\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+class CConnection
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ CSocket m_Socket;
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CConnection();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CConnection();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool initialize();
+ // open port
+ bool openPort();
+ // close port
+ bool closePort();
+ // accept
+ bool accept();
+ // connection
+ bool connection();
+ // disconnection
+ bool disconnection();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool setSendData(const CommunicationBuffer* in_pCommunicationBuffer);
+ bool getReceiveData(CommunicationBuffer** out_ppCommunicationBuffer);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool isConnect() const
+ {
+ return m_Socket.isConnect();
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CConnection
--- /dev/null
+// \8b\9e
+#ifndef INC_CRingBuffer
+#define INC_CRingBuffer
+
+
+#include <vector>
+
+////////////////////////////////////////////////////////////////////////////////
+// CRingBuffer
+////////////////////////////////////////////////////////////////////////////////
+template<typename T>
+class CRingBuffer
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ std::vector<T> m_Buffer;
+ int m_ReadPosition;
+ int m_WritePosition;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CRingBuffer()
+ {
+ m_ReadPosition = 0;
+ m_WritePosition = 0;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CRingBuffer()
+ {
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool allocate(unsigned int in_Size)
+ {
+ if(in_Size < 2){
+ return false;
+ }
+
+ m_Buffer.resize(in_Size);
+ m_ReadPosition = 0;
+ m_WritePosition = 0;
+ return true;
+ }
+
+ void clear()
+ {
+ m_Buffer.clear();
+ m_ReadPosition = 0;
+ m_WritePosition = 0;
+ }
+
+ bool nextReadBuffer()
+ {
+ if(empty()){
+ return false;
+ }
+
+ m_ReadPosition = (m_ReadPosition + 1) % m_Buffer.size();
+ return true;
+ }
+
+ bool nextWriteBuffer()
+ {
+ if(full()){
+ return false;
+ }
+
+ m_WritePosition = (m_WritePosition + 1) % m_Buffer.size();
+ return true;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ size_t size() const
+ {
+ return m_Buffer.size();
+ }
+
+ T* at(size_t in_Index)
+ {
+ return &m_Buffer[in_Index];
+ }
+
+ const T* at(size_t in_Index) const
+ {
+ return &m_Buffer[in_Index];
+ }
+
+ T* getReadPointer()
+ {
+ return &m_Buffer[m_ReadPosition];
+ }
+
+ const T* getReadPointer() const
+ {
+ return &m_Buffer[m_ReadPosition];
+ }
+
+ T* getWritePointer()
+ {
+ return &m_Buffer[m_WritePosition];
+ }
+
+ const T* getWritePointer() const
+ {
+ return &m_Buffer[m_WritePosition];
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // check if the buffer is full
+ bool full() const
+ {
+ return m_ReadPosition == (m_WritePosition + 1) % m_Buffer.size();
+ }
+
+ // check if the buffer is empty
+ bool empty() const
+ {
+ return m_ReadPosition == m_WritePosition;;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CRingBuffer
--- /dev/null
+#include <winsock2.h>
+#include <iostream>
+
+#include "CServerSocket.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// \83R\83\93\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CServerSocket::CServerSocket()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83f\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CServerSocket::~CServerSocket()
+{
+ uninitialize();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8f\89\8aú\89»
+////////////////////////////////////////////////////////////////////////////////
+bool CServerSocket::initialize()
+{
+ // \82Ç\82Á\82©\82Å\83V\83\93\83O\83\8b\83g\83\93\82ð\8eg\82Á\82Ä\8f\89\8aú\89»\82µ\82Ä\82¨\82
+ int a_Error = WSAStartup(MAKEWORD(2,0), &m_WsaData);
+ if(a_Error != 0){
+ switch(a_Error){
+ case WSASYSNOTREADY:
+ throw "WSASYSNOTREADY";
+ break;
+ case WSAVERNOTSUPPORTED:
+ throw "WSAVERNOTSUPPORTED";
+ break;
+ case WSAEINPROGRESS:
+ throw "WSAEINPROGRESS";
+ break;
+ case WSAEPROCLIM:
+ throw "WSAEPROCLIM";
+ break;
+ case WSAEFAULT:
+ throw "WSAEFAULT";
+ break;
+ }
+ return false;
+ }
+
+ /*
+ std::cout << "\83o\81[\83W\83\87\83\93 = " << static_cast<int>(wsaData.wHighVersion) << "." << static_cast<int>(wsaData.wHighVersion >> 8) << "\n"
+ << "description = " << wsaData.szDescription << "\n"
+ << "status = " << wsaData.szSystemStatus << "\n" << std::endl;
+ */
+
+ m_ServerSocket = socket(AF_INET, SOCK_STREAM, 0);
+ if(m_ServerSocket == INVALID_SOCKET){
+ //std::cout << "socket failed: " << WSAGetLastError() << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \94ñ\8f\89\8aú\89»
+////////////////////////////////////////////////////////////////////////////////
+bool CServerSocket::uninitialize()
+{
+ closePort();
+ WSACleanup();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// open port
+////////////////////////////////////////////////////////////////////////////////
+bool CServerSocket::openPort()
+{
+ // \83\\83P\83b\83g\82Ì\90Ý\92è
+ m_ServerSocketAddress.sin_family = AF_INET;
+ m_ServerSocketAddress.sin_port = htons(12345);
+ m_ServerSocketAddress.sin_addr.S_un.S_addr = INADDR_ANY;
+ BOOL yes = 1;
+ setsockopt(m_ServerSocket, SOL_SOCKET, SO_REUSEADDR, (const char *)&yes, sizeof(yes));
+ bind(m_ServerSocket, reinterpret_cast<sockaddr*>(&m_ServerSocketAddress), sizeof(m_ServerSocketAddress));
+
+ // TCP\83N\83\89\83C\83A\83\93\83g\82©\82ç\82Ì\90Ú\91±\97v\8b\81\82ð\91Ò\82Ä\82é\8fó\91Ô\82É\82·\82é
+ listen(m_ServerSocket, 5);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// close port
+////////////////////////////////////////////////////////////////////////////////
+bool CServerSocket::closePort()
+{
+ closesocket(m_ServerSocket);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// accept
+////////////////////////////////////////////////////////////////////////////////
+bool CServerSocket::accept(CSocket* io_pSocket)
+{
+ try{
+ m_NonConnectedSockets.push_back(io_pSocket);
+ }
+ catch(...){
+ return false;
+ }
+ if(!m_isExist){
+ start(true);
+ }
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83N\83\89\83C\83A\83\93\83g\82©\82ç\82Ì\90Ú\91±\82ð\91Ò\82Â
+////////////////////////////////////////////////////////////////////////////////
+void CServerSocket::run()
+{
+ // TCP\83N\83\89\83C\83A\83\93\83g\82©\82ç\82Ì\90Ú\91±\97v\8b\81\82ð\8eó\82¯\95t\82¯\82é
+ if(!m_NonConnectedSockets.empty()){
+ SOCKET a_ClientSocket;
+ sockaddr_in a_ClientSocketAddress;
+ int a_Length = sizeof(a_ClientSocketAddress);
+
+ a_ClientSocket = ::accept(m_ServerSocket, reinterpret_cast<sockaddr*>(&a_ClientSocketAddress), &a_Length);
+ if(a_ClientSocket == INVALID_SOCKET){
+ m_doLoop = false;
+ return;
+ }
+
+ std::cout << "accepted connection from " << inet_ntoa(a_ClientSocketAddress.sin_addr) << ", port = " << ntohs(a_ClientSocketAddress.sin_port) << std::endl;
+
+ // \96¢\90Ú\91±\82©\82ç\90Ú\91±\8dÏ\82Ý\82É\88Ú\93®\82·\82é
+ m_NonConnectedSockets.front()->connection(&a_ClientSocket, &a_ClientSocketAddress);
+ m_ConnectedSockets.push_back(m_NonConnectedSockets.front());
+ m_NonConnectedSockets.pop_front();
+ }
+
+ // \90Ú\91±\8dÏ\82Ý\82Ì\92\86\82©\82ç\90Ú\91±\82ª\8fI\97¹\82µ\82½\82à\82Ì\82ð\92T\8dõ\82µ\81A\96¢\90Ú\91±\82É\88Ú\93®\82·\82é
+ // \90Ú\91±\82ª\8fI\97¹\82µ\82Ä\82\82ê\82½CSocket\82ª\92Ê\92m\82µ\82Ä\82\82ê\82é\82Æ\8cø\97¦\82ª\82æ\82¢
+ std::list<CSocket*>::iterator p = m_ConnectedSockets.begin();
+ const std::list<CSocket*>::iterator end = m_ConnectedSockets.end();
+ while(true){
+ if(p == end){
+ break;
+ }
+
+ if(!(*p)->isConnect()){
+ // \96¢\90Ú\91±
+ m_NonConnectedSockets.push_back(*p);
+ p = m_ConnectedSockets.erase(p);
+ continue;
+ }
+ p++;
+ }
+}
--- /dev/null
+#ifndef INC_CServerSocket
+#define INC_CServerSocket
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+// winsock2.h\82Íwindows.h\82æ\82è\90æ\82É\83C\83\93\83N\83\8b\81[\83h\82µ\82È\82¯\82ê\82Î\82È\82ç\82È\82¢\82ç\82µ\82¢
+//#include <winsock2.h>
+#include "CThread.h"
+#include "CSocket.h"
+
+#include <list>
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CServerSocket
+////////////////////////////////////////////////////////////////////////////////
+class CServerSocket : public CThread
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ WSADATA m_WsaData;
+ // \8e©\95ª\8e©\90g\82Ì\83\\83P\83b\83g
+ SOCKET m_ServerSocket;
+ sockaddr_in m_ServerSocketAddress;
+
+ std::list<CSocket*> m_NonConnectedSockets;
+ std::list<CSocket*> m_ConnectedSockets;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CServerSocket();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CServerSocket();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8f\89\8aú\89»
+ bool initialize();
+ // \94ñ\8f\89\8aú\89»
+ bool uninitialize();
+ // open port
+ bool openPort();
+ // close port
+ bool closePort();
+ // accept
+ bool accept(CSocket* io_pSocket);
+
+protected:
+ // \83X\83\8c\83b\83h\83\8b\81[\83v
+ void run();
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \90Ú\91±\8b\96\89Â\82µ\82½\83N\83\89\83C\83A\83\93\83g\82ð\8eæ\93¾\82·\82é
+ //CSocket* getAcceptSocket();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CServerSocket
--- /dev/null
+#include <winsock2.h>
+#include <iostream>
+
+#include "CSocket.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// \83R\83\93\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CSocket::CSocket()
+{
+ m_isConnect = false;
+ m_Buffer.allocate(100);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83f\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CSocket::~CSocket()
+{
+ uninitialize();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8f\89\8aú\89»
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::initialize()
+{
+ int a_Error = WSAStartup(MAKEWORD(2,0), &m_WsaData);
+ if(a_Error != 0){
+ switch(a_Error){
+ case WSASYSNOTREADY:
+ throw "WSASYSNOTREADY";
+ break;
+ case WSAVERNOTSUPPORTED:
+ throw "WSAVERNOTSUPPORTED";
+ break;
+ case WSAEINPROGRESS:
+ throw "WSAEINPROGRESS";
+ break;
+ case WSAEPROCLIM:
+ throw "WSAEPROCLIM";
+ break;
+ case WSAEFAULT:
+ throw "WSAEFAULT";
+ break;
+ }
+ return false;
+ }
+
+ /*
+ std::cout << "\83o\81[\83W\83\87\83\93 = " << static_cast<int>(wsaData.wHighVersion) << "." << static_cast<int>(wsaData.wHighVersion >> 8) << "\n"
+ << "description = " << wsaData.szDescription << "\n"
+ << "status = " << wsaData.szSystemStatus << "\n" << std::endl;
+ */
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \94ñ\8f\89\8aú\89»
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::uninitialize()
+{
+ disconnection();
+ WSACleanup();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// connection
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::connection(SOCKET* io_pSocket, sockaddr_in* io_pSockAddress)
+{
+ // \96³\8cø\82È\83\\83P\83b\83g\82Ì\8fê\8d\87\81A\90V\8bK\8dì\90¬\82·\82é
+ if(io_pSocket == NULL){
+ m_Socket = socket(AF_INET, SOCK_STREAM, 0);
+ if(m_Socket == INVALID_SOCKET){
+ //std::cout << "socket failed: " << WSAGetLastError() << std::endl;
+ return false;
+ }
+
+ m_SocketAddress.sin_family = AF_INET;
+ m_SocketAddress.sin_port = htons(12345);
+ m_SocketAddress.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
+ connect(m_Socket, reinterpret_cast<sockaddr*>(&m_SocketAddress), sizeof(m_SocketAddress));
+ }
+ else{
+ m_Socket = *io_pSocket;
+ m_SocketAddress = *io_pSockAddress;
+ }
+ m_isConnect = true;
+
+ start(true);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// disconnection
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::disconnection()
+{
+ closesocket(m_Socket);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// shutdown
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::shutdown(unsigned int in_Kind)
+{
+ int a_Result = SOCKET_ERROR;
+ switch(in_Kind){
+ case 0:
+ // \91\97\90M\92\86\8e~
+ a_Result = ::shutdown(m_Socket, SD_SEND);
+ break;
+ case 1:
+ // \8eó\90M\92\86\8e~
+ a_Result = ::shutdown(m_Socket, SD_RECEIVE);
+ break;
+ case 2:
+ // \91\97\8eó\90M\92\86\8e~
+ a_Result = ::shutdown(m_Socket, SD_BOTH);
+ break;
+ default:
+ // \96³\8cø\82È\83R\83}\83\93\83h
+ throw "UNKNOWN COMMAND.";
+ break;
+ }
+ if(a_Result == SOCKET_ERROR){
+ return false;
+ }
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// send
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::send(const CommunicationBuffer* in_pCommunicationBuffer)
+{
+ ::send(m_Socket, in_pCommunicationBuffer->m_Buffer, in_pCommunicationBuffer->m_Length, 0);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// receive
+////////////////////////////////////////////////////////////////////////////////
+bool CSocket::receive(CommunicationBuffer** out_ppCommunicationBuffer)
+{
+ if(m_Buffer.empty()){
+ return false;
+ }
+
+ *out_ppCommunicationBuffer = m_Buffer.getReadPointer();
+ m_Buffer.nextReadBuffer();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8eó\90M\82ð\8ds\82¤
+////////////////////////////////////////////////////////////////////////////////
+void CSocket::run()
+{
+ if(!m_Buffer.full()){
+ m_Buffer.getWritePointer()->m_Length = recv(m_Socket, m_Buffer.getWritePointer()->m_Buffer, MAX_STRING_BUFFER_SIZE, 0);
+ if(m_Buffer.getWritePointer()->m_Length == 0){
+ std::cout << "disconnection" << std::endl;
+ m_isConnect = false;
+ m_doLoop = false;
+ return;
+ }
+ else if(m_Buffer.getWritePointer()->m_Length == SOCKET_ERROR){
+ std::cout << "socket error" << std::endl;
+ m_isConnect = false;
+ m_doLoop = false;
+ return;
+ }
+
+ //std::cout << m_Buffer.getWritePointer()->m_Buffer << std::endl;
+ m_Buffer.nextWriteBuffer();
+ }
+}
--- /dev/null
+#ifndef INC_CSocket
+#define INC_CSocket
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+// winsock2.h\82Íwindows.h\82æ\82è\90æ\82É\83C\83\93\83N\83\8b\81[\83h\82µ\82È\82¯\82ê\82Î\82È\82ç\82È\82¢\82ç\82µ\82¢
+//#include <winsock2.h>
+#include "CThread.h"
+#include "CRingBuffer.h"
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+const int MAX_STRING_BUFFER_SIZE = 256;
+
+struct CommunicationBuffer
+{
+ char m_Buffer[MAX_STRING_BUFFER_SIZE];
+ // \8ai\94[\82³\82ê\82Ä\82¢\82é\95¶\8e\9a\90\94
+ size_t m_Length;
+
+ CommunicationBuffer()
+ {
+ m_Length = 0;
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// CSocket
+////////////////////////////////////////////////////////////////////////////////
+class CSocket : public CThread
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ WSADATA m_WsaData;
+ SOCKET m_Socket;
+ sockaddr_in m_SocketAddress;
+
+ bool m_isConnect;
+
+ CRingBuffer<CommunicationBuffer> m_Buffer;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CSocket();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CSocket();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8f\89\8aú\89»
+ bool initialize();
+ // \94ñ\8f\89\8aú\89»
+ bool uninitialize();
+ // connection
+ bool connection(SOCKET* io_pSocket = NULL, sockaddr_in* io_pSockAddress = NULL);
+ // disconnection
+ bool disconnection();
+ // shutdown
+ bool shutdown(unsigned int in_Kind);
+ // send
+ bool send(const CommunicationBuffer* in_pCommunicationBuffer);
+ // receive
+ bool receive(CommunicationBuffer** out_ppCommunicationBuffer);
+
+protected:
+ // \83X\83\8c\83b\83h\83\8b\81[\83v
+ void run();
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ SOCKET* getSocket()
+ {
+ return &m_Socket;
+ }
+
+ sockaddr* getSocketAddress()
+ {
+ return reinterpret_cast<sockaddr*>(&m_SocketAddress);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool isConnect() const
+ {
+ return m_isConnect;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CSocket
--- /dev/null
+// \8b\9e
+
+#include "CThread.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// \83R\83\93\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CThread::CThread()
+{
+ m_hThread = NULL;
+ m_doLoop = false;
+ m_isExist = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83f\83X\83g\83\89\83N\83^
+////////////////////////////////////////////////////////////////////////////////
+CThread::~CThread()
+{
+ CriticalSectionID begin = m_CriticalSectionList.begin();
+ CriticalSectionID end = m_CriticalSectionList.end();
+ for(CriticalSectionID p = begin; p != end; p++){
+ DeleteCriticalSection(*p);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\83R\81[\83\8b\83o\83b\83N\97p
+////////////////////////////////////////////////////////////////////////////////
+unsigned int __stdcall CThread::procThread(void* in_pParameter)
+{
+ CThread* pClass = static_cast<CThread*>(in_pParameter);
+
+ while(pClass->m_isExist){
+ pClass->run();
+
+ if(!pClass->m_doLoop){
+ break;
+ }
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \91\80\8dì\83\81\83\\83b\83h
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82ð\8aJ\8en\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+bool CThread::start(bool in_doLoop, UINT in_Flag)
+{
+ // \83f\83t\83H\83\8b\83g\82Å\82Í\82·\82®\82É\8aJ\8en\82·\82é
+ // CREATE_SUSPENDED\82ð\8ew\92è\82Å\83T\83X\83y\83\93\83h
+
+ UINT ThreadId;
+ m_hThread = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, procThread, this, in_Flag, &ThreadId));
+ if(m_hThread == NULL){
+ return false;
+ }
+ m_doLoop = in_doLoop;
+ m_isExist = true;
+
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82ð\8fI\97¹\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+void CThread::stop()
+{
+ if(m_isExist){
+ m_isExist = false;
+
+ if(m_hThread != NULL){
+ // \83X\83\8c\83b\83h\82Ì\8fI\97¹\82ð\91Ò\82Â
+ ::WaitForSingleObject(m_hThread, INFINITE);
+ // \83X\83\8c\83b\83h\83n\83\93\83h\83\8b\82ð\95Â\82¶\82é
+ ::CloseHandle(m_hThread);
+ m_hThread = NULL;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82ð\88ê\8e\9e\92â\8e~\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+UINT CThread::suspend()
+{
+ DWORD Status = ::SuspendThread(m_hThread);
+ if(Status == 0xFFFFFFFF){
+ return ::GetLastError();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82ð\8dÄ\83X\83^\81[\83g\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+UINT CThread::resume()
+{
+ DWORD Status = ::ResumeThread(m_hThread);
+ if(Status == 0xFFFFFFFF){
+ return ::GetLastError();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\83\8b\81[\83v
+////////////////////////////////////////////////////////////////////////////////
+void CThread::run()
+{
+ Sleep(100);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\90§\8cäID\82ð\8eæ\93¾\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+const CriticalSectionID CThread::createCriticalSectionID()
+{
+ MyCriticalSection* temp = new MyCriticalSection;
+ InitializeCriticalSection(temp);
+ m_CriticalSectionList.push_front(temp);
+ return m_CriticalSectionList.begin();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\90§\8cäID\82ð\8aJ\95ú\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+void CThread::deleteCriticalSectionID(const CriticalSectionID in_CriticalSectionID)
+{
+ DeleteCriticalSection(*in_CriticalSectionID);
+ m_CriticalSectionList.erase(in_CriticalSectionID);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\82É\93ü\82é
+////////////////////////////////////////////////////////////////////////////////
+void CThread::enterCriticalSectionID(const CriticalSectionID in_CriticalSectionID)
+{
+ EnterCriticalSection(*in_CriticalSectionID);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\82©\82ç\8fo\82é
+////////////////////////////////////////////////////////////////////////////////
+void CThread::leaveCriticalSectionID(const CriticalSectionID in_CriticalSectionID)
+{
+ LeaveCriticalSection(*in_CriticalSectionID);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \91®\90«\83\81\83\\83b\83h
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+// \83v\83\8d\83Z\83X\83v\83\89\83C\83I\83\8a\83e\83B\82Ì\90Ý\92è
+////////////////////////////////////////////////////////////////////////////////
+UINT CThread::setPriorityClass(DWORD in_PriorityClass)
+{
+ // \97D\90æ\8f\87\88Ê\83N\83\89\83X\82ª\8dÅ\8d\82\82Ì\8e\9e\82Í\88À\91S\82Ì\88×\81A\83G\83\89\81[\82Æ\82µ\82Ä\95Ô\82·\81B
+ if(in_PriorityClass == REALTIME_PRIORITY_CLASS){
+ return -1;
+ }
+
+ BOOL Status = ::SetPriorityClass(m_hThread, in_PriorityClass);
+ if(!Status){
+ return ::GetLastError();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82Ì\97D\90æ\93x\82ð\90Ý\92è\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+UINT CThread::setPriority(int in_Priority)
+{
+ BOOL Status = ::SetThreadPriority(m_hThread, in_Priority);
+ if(!Status){
+ return ::GetLastError();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82Ì\97D\90æ\93x\82ð\97D\90æ\93x\82ð\8dÅ\92á( = 1)\82É\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+UINT CThread::setPriorityMinimum()
+{
+ BOOL Status = ::SetThreadPriority(m_hThread, THREAD_PRIORITY_IDLE);
+ if(!Status){
+ return ::GetLastError();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82Ì\97D\90æ\93x\82ð\97D\90æ\93x\82ð\8dÅ\91å( = 15)\82É\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+UINT CThread::setPriorityMaxisim()
+{
+ BOOL Status = ::SetThreadPriority(m_hThread, THREAD_PRIORITY_TIME_CRITICAL);
+ if(!Status){
+ return ::GetLastError();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8fó\91Ô
+////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+// \83X\83\8c\83b\83h\82ª\91¶\8dÝ\82·\82é\82©\92²\82×\82é
+////////////////////////////////////////////////////////////////////////////////
+bool CThread::isExist()
+{
+ return m_isExist;
+}
--- /dev/null
+// \8b\9e
+
+#ifndef INC_CThread
+#define INC_CThread
+
+#include <windows.h>
+#include <process.h>
+#include <list>
+
+typedef CRITICAL_SECTION MyCriticalSection;
+typedef std::list<MyCriticalSection*> CriticalSectionList;
+typedef CriticalSectionList::iterator CriticalSectionID;
+
+////////////////////////////////////////////////////////////////////////////////
+// CThread
+// Windows\97p\83X\83\8c\83b\83h\83N\83\89\83X
+////////////////////////////////////////////////////////////////////////////////
+class CThread
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+protected:
+ // Windows\97p\83X\83\8c\83b\83h\90§\8cä\97p
+ HANDLE m_hThread;
+ // \83X\83\8c\83b\83h\8aÖ\90\94\83\8b\81[\83v\8aÇ\97\9d\97p
+ bool m_doLoop;
+ // \83X\83\8c\83b\83h\91¶\8dÝ\8aÇ\97\9d\97p
+ bool m_isExist;
+
+private:
+ // \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\90§\8cä\97p
+ CriticalSectionList m_CriticalSectionList;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CThread();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ virtual ~CThread();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+protected:
+ static unsigned int __stdcall procThread(void* in_pParameter);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \83X\83^\81[\83g(DoLoop: true - \8cJ\82è\95Ô\82·, false - \88ê\89ñ\82Ì\82Ý, Flag: \83X\83\8c\83b\83h\82Ì\90Ý\92è)
+ virtual bool start(bool in_doLoop = false, UINT in_Flag = 0);
+ // \83X\83g\83b\83v
+ virtual void stop();
+ // \88ê\8e\9e\92â\8e~
+ virtual UINT suspend();
+ // \83X\83\8c\83b\83h\8dÄ\83X\83^\81[\83g
+ virtual UINT resume();
+protected:
+ // \83X\83\8c\83b\83h\83\8b\81[\83v
+ virtual void run();
+
+public:
+ // \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\90§\8cäID\82ð\8eæ\93¾\82·\82é
+ const CriticalSectionList::iterator createCriticalSectionID();
+ // \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\90§\8cäID\82ð\8aJ\95ú\82·\82é
+ void deleteCriticalSectionID(const CriticalSectionID in_CriticalSectionID);
+ // \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\82É\93ü\82é
+ void enterCriticalSectionID(const CriticalSectionID in_CriticalSectionID);
+ // \83N\83\8a\83e\83B\83J\83\8b\83Z\83N\83V\83\87\83\93\82©\82ç\8fo\82é
+ void leaveCriticalSectionID(const CriticalSectionID in_CriticalSectionID);
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \83v\83\8d\83Z\83X\83v\83\89\83C\83I\83\8a\83e\83B\82Ì\90Ý\92è
+ virtual UINT setPriorityClass(DWORD in_PriorityClass);
+ // \97D\90æ\93x\82Ì\90Ý\92è
+ virtual UINT setPriority(int in_Priority);
+ // \97D\90æ\93x\82ð\8dÅ\92á\82É\82·\82é
+ virtual UINT setPriorityMinimum();
+ // \97D\90æ\93x\82ð\8dÅ\91å\82É\82·\82é
+ virtual UINT setPriorityMaxisim();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \83X\83\8c\83b\83h\82ª\91¶\8dÝ\82·\82é\82©\92²\82×\82é
+ virtual bool isExist();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+};
+
+#endif //INC_CThread
--- /dev/null
+// \8b\9e
+
+#ifndef INC_DATA
+#define INC_DATA
+
+// \83A\83o\83^\81[\82Ì\8fî\95ñ
+struct AvatarInformation
+{
+ // \83L\83\83\83\89\83N\83^\81[\96¼
+ char m_Name[256];
+ // \8dÀ\95W
+ double m_Position[3];
+ // \95û\8cü
+ double m_Direction[3];
+ // \83T\83C\83Y
+ double m_Radias;
+};
+
+#endif // INC_DATA
--- /dev/null
+// \8b\9e
+
+#ifdef WIN32
+ #pragma warning(disable : 4244) // MIPS
+ #pragma warning(disable : 4136) // X86
+ #pragma warning(disable : 4051) // ALPHA
+
+ //#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
+
+ // \8cÃ\82¢\8aÖ\90\94\82Ì\8cx\8d\90\82ð\92â\8e~
+ #pragma warning(disable: 4996)
+ #pragma warning(disable: 4786)
+#endif // WIN32
+
+
+
+
+#ifndef INC_ENVIRONMENT
+#define INC_ENVIRONMENT
+
+#endif // INC_ENVIRONMENT
--- /dev/null
+\81\9b\83f\83B\83\8c\83N\83g\83\8a\82Ì\8eg\82¢\95û
+\81uOS\81v\81A\81u\83R\83\93\83p\83C\83\89\81v\81A\81u\8b@\94\\81v\82²\82Æ\82É\83f\83B\83\8c\83N\83g\83\8a\82ð\8dì\90¬\82µ\81A\82»\82ê\82¼\82ê\82Ì\96¼\91O\82ð\95t\82¯\82é\81B
+ \97á
+ OS: Linux\81A\83R\83\93\83p\83C\83\89: gcc\81A\8b@\94\: \83N\83\89\83C\83A\83\93\83g\82Ì\8fê\8d\87\81A\81ulinux_gcc_client\81v
+
+
+\97á\8aO
+ \91¼\82Ì\97v\91f\82Å\95K\82¸\8c\88\82Ü\82é\82à\82Ì\82Í\8fÈ\82
+ \97á
+ Visual C++\82Ì\82æ\82¤\82È\83R\83\93\83p\83C\83\89\82Í\81AOS\82ªWindows\8cÀ\92è\82È\82Ì\82Å\81AOS\96¼\82Í\8fÈ\82
+ vc2010_client
+
+
+
+
+
+\81\9b\82¨\92m\82ç\82¹\81i\91¼\82Ì\90l\82Ö\82Ì\88ê\8c¾\81j
+OS\82â\83R\83\93\83p\83C\83\89\82É\88Ë\91¶\82µ\82È\82¢\83\\81[\83X\83R\81[\83h\82ð\88ê\82Â\82É\82Ü\82Æ\82ß\8dÄ\97\98\97p\82µ\82â\82·\82¢\82æ\82¤\82É\82·\82é\81Bcommon\83f\83B\83\8c\83N\83g\83\8a\81B
+
+\81¦\90V\82½\82È\83\8b\81[\83\8b\81A\91¼\82Ì\90l\82Ö\82Ì\82¨\92m\82ç\82¹\82ª\82 \82é\8fê\8d\87\82Í\90\8f\8e\9e\8dX\90V\82µ\82Ä\82\82¾\82³\82¢\81B
+
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual C++ Express 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vc2010_client", "vc2010_client\vc2010_client.vcxproj", "{B25CF9CE-B08B-4647-A84F-C5B9B13D42AB}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B25CF9CE-B08B-4647-A84F-C5B9B13D42AB}.Debug|Win32.ActiveCfg = Debug|Win32
+ {B25CF9CE-B08B-4647-A84F-C5B9B13D42AB}.Debug|Win32.Build.0 = Debug|Win32
+ {B25CF9CE-B08B-4647-A84F-C5B9B13D42AB}.Release|Win32.ActiveCfg = Release|Win32
+ {B25CF9CE-B08B-4647-A84F-C5B9B13D42AB}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
--- /dev/null
+#include "CClient.h"
+
+#include <iostream>
+
+////////////////////////////////////////////////////////////////////////////////
+// constructor
+////////////////////////////////////////////////////////////////////////////////
+CClient::CClient()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// destructor
+////////////////////////////////////////////////////////////////////////////////
+CClient::~CClient()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// initialize
+////////////////////////////////////////////////////////////////////////////////
+bool CClient::initialize()
+{
+ m_UI.setModel(&m_Model);
+ m_UI.initialize();
+ m_Model.initialize();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// mail loop
+////////////////////////////////////////////////////////////////////////////////
+void CClient::mainloop()
+{
+ // \82Æ\82è\82 \82¦\82¸\96³\8cÀ\83\8b\81[\83v\82É\93ü\82é
+
+ m_UI.start();
+
+ while(true){
+ if(m_UI.existEvent()){
+ ClientInputEvent a_Event = m_UI.getEvent();
+ if(a_Event == "CONNECT"){
+ m_Model.addEvent("CONNECT");
+ }
+ else if(a_Event == "DISCONNECT"){
+ m_Model.addEvent("DISCONNECT");
+ }
+ else if(a_Event == "LOGIN"){
+ m_Model.addEvent("LOGIN");
+ }
+ else if(a_Event == "LOGOUT"){
+ m_Model.addEvent("LOGOUT");
+ }
+ else if(a_Event == "POSITION"){
+ m_Model.addEvent("POSITION");
+ }
+ else if(a_Event == "END"){
+ break;
+ }
+ }
+ m_Model.process();
+ Sleep(1);
+ }
+}
--- /dev/null
+#ifndef INC_CClient
+#define INC_CClient
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "CClientModel.h"
+#include "CClientUI.h"
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CClient
+////////////////////////////////////////////////////////////////////////////////
+class CClient
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ CClientUI m_UI;
+ CClientModel m_Model;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CClient();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CClient();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8f\89\8aú\89»
+ bool initialize();
+ // main loop
+ void mainloop();
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8bN\93®\83p\83\89\83\81\81[\83^\82ð\93ü\97Í\82·\82é
+ void setArgement(int* in_pArgc, char** in_ppArgv)
+ {
+ m_UI.setArgement(in_pArgc, in_ppArgv);
+ }
+
+public:
+ // \83\8d\83O\83C\83\93\96¼\82ð\93ü\97Í\82·\82é
+ void setLoginName(std::string in_LoginName)
+ {
+ m_Model.setLoginName(in_LoginName);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CClient
--- /dev/null
+// \8b\9e
+#include "../../common/Environment.h"
+
+#include "CClientModel.h"
+
+#include <iostream>
+#include <string>
+
+////////////////////////////////////////////////////////////////////////////////
+// constructor
+////////////////////////////////////////////////////////////////////////////////
+CClientModel::CClientModel()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// destructor
+////////////////////////////////////////////////////////////////////////////////
+CClientModel::~CClientModel()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// initialize
+////////////////////////////////////////////////////////////////////////////////
+bool CClientModel::initialize()
+{
+ //m_Connection.initialize();
+ m_Socket.initialize();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83C\83x\83\93\83g\92Ç\89Á
+////////////////////////////////////////////////////////////////////////////////
+bool CClientModel::addEvent(std::string in_Event)
+{
+ m_Events.push_back(in_Event);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8f\88\97\9d
+////////////////////////////////////////////////////////////////////////////////
+bool CClientModel::process()
+{
+ // \92Ê\90M\83N\83\89\83X\82©\82ç\83f\81[\83^\8eæ\93¾
+ CommunicationBuffer* a_pBuffer;
+#if 0
+ if(m_Connection.getReceiveData(&a_pBuffer)){
+ std::cout << a_pBuffer->m_Buffer << std::endl;
+ }
+#else
+ if(m_Socket.receive(&a_pBuffer)){
+ std::cout << a_pBuffer->m_Buffer << std::endl;
+ }
+#endif
+
+ // \83C\83x\83\93\83g\8f\88\97\9d
+ if(!m_Events.empty()){
+ std::string& a_rEvent = m_Events.front();
+ // connect
+ if(a_rEvent == "CONNECT"){
+ //m_Connection.connection();
+ m_Socket.connection();
+ }
+ // disconnect
+ else if(a_rEvent == "DISCONNECT"){
+ //m_Connection.disconnection();
+ m_Socket.disconnection();
+ }
+ // \83\8d\83O\83C\83\93\8f\88\97\9d
+ else if(a_rEvent == "LOGIN"){
+ CommunicationBuffer a_SendBuffer;
+ a_SendBuffer.m_Length = sprintf(a_SendBuffer.m_Buffer, "i:%s;", m_LoginName.c_str());
+ //m_Connection.setSendData(&a_SendBuffer);
+ m_Socket.send(&a_SendBuffer);
+ }
+ // \83\8d\83O\83A\83E\83g
+ else if(a_rEvent == "LOGOUT"){
+ CommunicationBuffer a_SendBuffer;
+ a_SendBuffer.m_Length = sprintf(a_SendBuffer.m_Buffer, "o;", m_LoginName.c_str());
+ //m_Connection.setSendData(&a_SendBuffer);
+ m_Socket.send(&a_SendBuffer);
+ }
+
+ m_Events.pop_front();
+ }
+
+ // \83A\83N\83V\83\87\83\93\83R\83}\83\93\83h\82ð\8f\88\97\9d
+
+ // \89¹\90º\82ð\8d\87\90¬
+
+ // \8eæ\93¾\83R\83}\83\93\83h\82É\91Î\82µ\82Ä\83f\81[\83^\91\97\90M
+
+ return true;
+}
--- /dev/null
+#ifndef INC_CClientModel
+#define INC_CClientModel
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "../../common/Data.h"
+#include "../../common/CConnection.h"
+#include "../../common/CSocket.h"
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CClientModel
+////////////////////////////////////////////////////////////////////////////////
+class CClientModel
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ // \83A\83o\83^\81[\8fî\95ñ
+ AvatarInformation m_AvatarInformation;
+ // \92Ê\90M\83N\83\89\83X
+ CConnection m_Connection;
+ CSocket m_Socket;
+
+ std::list<std::string> m_Events;
+
+ // \83\8d\83O\83C\83\93\96¼
+ std::string m_LoginName;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CClientModel();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CClientModel();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8f\89\8aú\89»
+ bool initialize();
+ // \83C\83x\83\93\83g\92Ç\89Á
+ bool addEvent(std::string);
+ // \8f\88\97\9d
+ bool process();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ void setLoginName(std::string in_LoginName)
+ {
+ m_LoginName = in_LoginName;
+ }
+
+ const AvatarInformation* getAvatarInformation()
+ {
+ return &m_AvatarInformation;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CClientModel
--- /dev/null
+#include "CClientUI.h"
+
+#include <iostream>
+
+#include <Windows.h>
+#include <cstdlib>
+#include <iostream>
+#include <cmath>
+#include <time.h>
+//#include <GL/glut.h>
+#include "glut.h"
+
+#pragma comment(lib, "ws2_32.lib")
+
+#ifndef M_PI
+#define M_PI 3.14159265357989
+#endif // M_PI
+
+
+// key status
+long g_KeyStatus = 0;
+const int KEY_UP_BIT = 1 << 0;
+const int KEY_DOWN_BIT = 1 << 1;
+const int KEY_RIGHT_BIT = 1 << 2;
+const int KEY_LEFT_BIT = 1 << 3;
+
+CClientUI* CClientUI::sm_pUI = NULL;
+
+////////////////////////////////////////////////////////////////////////////////
+// constructor
+////////////////////////////////////////////////////////////////////////////////
+CClientUI::CClientUI()
+{
+ sm_pUI = this;
+ m_isEnd = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// destructor
+////////////////////////////////////////////////////////////////////////////////
+CClientUI::~CClientUI()
+{
+ uninitialize();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \89æ\96Ê\82ð\95`\89æ\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::display()
+{
+ // clear buffer
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ // initialize modelview matrix
+ glLoadIdentity();
+
+ // \8dÀ\95W\8cn\82Ì\92è\8b`
+ // x-y\95½\96Ê\82ð\92n\96Ê
+ // z = 0\82ð\95W\8d\820
+
+ // set look at matrix
+ // \8c»\8fó\82Í\8fã\82©\82ç\8e\8b\93_\81i\8fã\8bó5m\81j\82Æ\82·\82é
+ gluLookAt(
+ 0, 0, 5, // \8e\8b\93_\82Ì\88Ê\92u
+ 0, 0, 0, // \8e\8b\93_\82Ì\96Ú\95W\92n\93_
+ 0, 1, 0 // \93ª\82Ì\8cü\82«
+ );
+
+ GLfloat position[] = {-1.0, 1.0, 1.0, 0.0};
+ glLightfv(GL_LIGHT0, GL_POSITION, position);
+
+ // \83A\83o\83^\81[\95`\89æ
+ // \8aÂ\8b«\90Ý\92è
+ GLfloat a_AmbientDiffuse[] = {1.0, 0.0, 0.0, 1.0};
+ GLfloat a_Specular[] = {1.0, 1.0, 1.0, 1.0};
+ GLfloat a_Shininess[] = {20.0};
+ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, a_AmbientDiffuse);
+ glMaterialfv(GL_FRONT, GL_SPECULAR, a_Specular);
+ glMaterialfv(GL_FRONT, GL_SHININESS, a_Shininess);
+ // set avatar color to white
+ glColor3f(1.0, 1.0, 1.0);
+
+
+ const AvatarInformation* a_pAvatarInformation = sm_pUI->m_pModel->getAvatarInformation();
+ glPushMatrix();
+ {
+ glTranslated(a_pAvatarInformation->m_Position[0], a_pAvatarInformation->m_Position[1], a_pAvatarInformation->m_Position[2]);
+ glutSolidSphere(a_pAvatarInformation->m_Radias, 10, 10);
+ glBegin(GL_LINES);
+ {
+ glVertex3d(0.0, 0.0, 0.0);
+ glVertex3d(a_pAvatarInformation->m_Direction[0], a_pAvatarInformation->m_Direction[1], a_pAvatarInformation->m_Direction[2]);
+ }
+ glEnd();
+ }
+ glPopMatrix();
+
+ glutSwapBuffers();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8f\89\8aú\89»\82·\82é
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::init()
+{
+ // background color is black
+ glClearColor(0.0, 0.0, 0.0, 1.0);
+
+ // \8aÂ\8b«\95Ï\90\94\90Ý\92è
+ GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
+ GLfloat diffuse[] = {0.6, 0.6, 0.6, 1.0};
+ GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
+ GLfloat position[] = {-1.0, 1.0, 1.0, 0.0};
+
+ //glEnable(GL_LIGHTING);
+ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
+ glLightfv(GL_LIGHT0, GL_POSITION, position);
+ //glEnable(GL_LIGHT0);
+
+ GLfloat material_ambient_diffuse[] = {1.0, 0.0, 0.0, 1.0};
+ GLfloat material_specular[] = {1.0, 1.0, 1.0, 1.0};
+ GLfloat material_shininess[] = {20.0};
+
+ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material_ambient_diffuse);
+ glMaterialfv(GL_FRONT, GL_SPECULAR, material_specular);
+ glMaterialfv(GL_FRONT, GL_SHININESS, material_shininess);
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_CULL_FACE);
+
+ //glShadeModel(GL_FLAT);
+
+ srand(static_cast<unsigned int>(time(NULL)));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \88ê\94Ê\83L\81[\93ü\97Í
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::keyboard(unsigned char in_Key, int in_x, int in_y)
+{
+ switch(in_Key){
+ case 'c':
+ // connect
+ sm_pUI->m_Events.push_back("CONNECT");
+ break;
+
+ case 'd':
+ // disconnect
+ sm_pUI->m_Events.push_back("DISCONNECT");
+ break;
+
+ case 'i':
+ // login
+ sm_pUI->m_Events.push_back("LOGIN");
+ break;
+
+ case 'o':
+ // logout
+ sm_pUI->m_Events.push_back("LOGOUT");
+ break;
+
+ case 'p':
+ // \8dÀ\95W\8eæ\93¾
+ sm_pUI->m_Events.push_back("POSITION");
+ break;
+
+
+ case 'q':
+ case 'Q':
+ case '\033': /* '\033' \82Í ESC \82Ì ASCII \83R\81[\83h */
+ sm_pUI->m_Events.push_back("END");
+ //exit(0);
+ default:
+ break;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// down special key
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::downSpecialKey(int in_Key, int in_x, int in_y)
+{
+ switch(in_Key){
+ case GLUT_KEY_UP:
+ g_KeyStatus |= KEY_UP_BIT;
+ break;
+ case GLUT_KEY_DOWN:
+ g_KeyStatus |= KEY_DOWN_BIT;
+ break;
+ case GLUT_KEY_RIGHT:
+ g_KeyStatus |= KEY_RIGHT_BIT;
+ break;
+ case GLUT_KEY_LEFT:
+ g_KeyStatus |= KEY_LEFT_BIT;
+ break;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// up special key
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::upSpecialKey(int in_Key, int in_x, int in_y)
+{
+ switch(in_Key){
+ case GLUT_KEY_UP:
+ g_KeyStatus &= ~KEY_UP_BIT;
+ break;
+ case GLUT_KEY_DOWN:
+ g_KeyStatus &= ~KEY_DOWN_BIT;
+ break;
+ case GLUT_KEY_RIGHT:
+ g_KeyStatus &= ~KEY_RIGHT_BIT;
+ break;
+ case GLUT_KEY_LEFT:
+ g_KeyStatus &= ~KEY_LEFT_BIT;
+ break;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// timer
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::timer(int value)
+{
+ // 1\95b\8aÔ\82É60\89ñ\8cÄ\82Ñ\8fo\82³\82ê\82é
+ glutTimerFunc(1000 / 60, timer, 0);
+
+ // \83L\81[\93ü\97Í\82Ì\8fó\91Ô\82É\82æ\82è\83A\83o\83^\81[\81ii = 0\82Ì\82Ý\81j\82ð\93®\82©\82·
+ // \91O\90i
+ if((g_KeyStatus & KEY_UP_BIT) && !(g_KeyStatus & KEY_DOWN_BIT)){
+ sm_pUI->m_Events.push_back("FRONT");
+ }
+ // \8cã\91Þ
+ else if(!(g_KeyStatus & KEY_UP_BIT) && (g_KeyStatus & KEY_DOWN_BIT)){
+ }
+ // \89E\90ù\89ñ
+ if((g_KeyStatus & KEY_RIGHT_BIT) && !(g_KeyStatus & KEY_LEFT_BIT)){
+ }
+ // \8d¶\90ù\89ñ
+ else if(!(g_KeyStatus & KEY_RIGHT_BIT) && (g_KeyStatus & KEY_LEFT_BIT)){
+ }
+
+
+ glutPostRedisplay();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \83T\83C\83Y\95Ï\8dX
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::reshape(int w, int h)
+{
+ glViewport(0, 0, (GLsizei) w, (GLsizei) h);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ if(w <= h){
+ glFrustum(-1.0, 1.0, -1.0 * (GLfloat)h / (GLfloat)w, 1.0 * (GLfloat)h / (GLfloat)w, 1.0, 30.0);
+ }
+ else{
+ glFrustum(-1.0 * (GLfloat)w / (GLfloat)h, 1.0 * (GLfloat)w / (GLfloat)h, -1.0, 1.0, 1.0, 30.0);
+ }
+ glMatrixMode(GL_MODELVIEW);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// start input
+////////////////////////////////////////////////////////////////////////////////
+bool CClientUI::initialize()
+{
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// stop input
+////////////////////////////////////////////////////////////////////////////////
+bool CClientUI::uninitialize()
+{
+ m_isEnd = true;
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// thread loop
+////////////////////////////////////////////////////////////////////////////////
+void CClientUI::run()
+{
+ glutInit(m_pArgc, m_ppArgv);
+ glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
+ glutInitWindowSize(512, 512);
+ glutCreateWindow("internetcity");
+ glutDisplayFunc(display);
+ glutKeyboardFunc(keyboard);
+ glutSpecialFunc(downSpecialKey);
+ glutSpecialUpFunc(upSpecialKey);
+ glutTimerFunc(1000 / 60, timer, 0);
+ glutReshapeFunc(reshape);
+ init();
+ glutMainLoop();
+}
+
+
--- /dev/null
+#ifndef INC_CClientUI
+#define INC_CClientUI
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "../../common/CThread.h"
+#include "CClientModel.h"
+#include <list>
+#include <string>
+
+typedef std::string ClientInputEvent;
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CClientUI
+////////////////////////////////////////////////////////////////////////////////
+class CClientUI : public CThread
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ static CClientUI* sm_pUI;
+ std::list<ClientInputEvent> m_Events;
+ bool m_isEnd;
+ int* m_pArgc;
+ char** m_ppArgv;
+
+ CClientModel* m_pModel;
+
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CClientUI();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CClientUI();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ static void display();
+ void init();
+ static void keyboard(unsigned char in_Key, int in_x, int in_y);
+ static void downSpecialKey(int in_Key, int in_x, int in_y);
+ static void upSpecialKey(int in_Key, int in_x, int in_y);
+ static void timer(int value);
+ static void reshape(int w, int h);
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // start input
+ bool initialize();
+ // stop input
+ bool uninitialize();
+ // thread loop
+ void run();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ void setArgement(int* in_pArgc, char** in_ppArgv)
+ {
+ m_pArgc = in_pArgc;
+ m_ppArgv = in_ppArgv;
+ }
+
+ ClientInputEvent getEvent()
+ {
+ ClientInputEvent temp = m_Events.front();
+ m_Events.pop_front();
+ return temp;
+ }
+
+ void setModel(CClientModel* io_pModel)
+ {
+ m_pModel = io_pModel;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool existEvent()
+ {
+ return !m_Events.empty();
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CClientUI
--- /dev/null
+// \8b\9e
+
+#include "../../common/Environment.h"
+
+#ifdef WIN32
+ //#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
+#endif // WIN32
+
+// \92Ê\90M\82É\82Â\82¢\82Ä
+// \89¹\90º\82ÍRTP\82ð\8eg\82Á\82Ä\92Ê\90M\82ð\8ds\82¢\82½\82¢\82ª\81A\8c»\8dÝ\83\89\83C\83u\83\89\83\8a\82Í\92²\8d¸\92\86\82Å\82 \82é\81B
+// \82³\82ç\82É\81A\83R\83}\83\93\83h\82Æ\89¹\90º\82Ì\90Ø\82è\95ª\82¯\82â\93¯\8aú\82à\8c»\8dÝ\8c\9f\93¢\92\86\82Å\82 \82é\81B
+// \82æ\82Á\82Ä\81A\8c»\92i\8aK\82Å\82Í\83R\83}\83\93\83h\82à\89¹\90º\82à\82·\82×\82ÄTCP\82ð\8eg\97p\82µ\82Ä\92Ê\90M\82ð\8ds\82¤\81B
+// TCP\82ð\8eg\97p\82·\82é\82½\82ß\81A\83R\83}\83\93\83h\82à\89¹\90º\82à\92x\89\84\82ª\90¶\82¶\82é\82Æ\8dl\82¦\82ç\82ê\82é\81B
+// \82³\82ç\82É\81A\89¹\90º\82Í\8fí\82É\91\97\90M\82ð\8ds\82Á\82Ä\82¢\82é\82½\82ß\81A\83o\83b\83t\83@\82ª\82 \82é\82ê\82é\82à\82Ì\82Æ\8dl\82¦\82ç\82ê\82é\81B
+// \82»\82Ì\8fê\8d\87\82Í\81A\90V\82µ\82¢\83R\83}\83\93\83h\82â\89¹\90º\82ð\94j\8aü\82·\82é\82±\82Æ\82Å\91Î\89\9e\82ð\8ds\82¤\81B
+// \82±\82ê\82ð\8ds\82¤\82±\82Æ\82É\82æ\82Á\82Ä\81A\83R\83}\83\93\83h\82ª\94½\89\9e\82µ\82È\82©\82Á\82½\82è\81A\89¹\90º\82ª\82Æ\82¬\82ê\82Æ\82¬\82ê\82É\82È\82é\82à\82Ì\82Æ\8dl\82¦\82ç\82ê\82é\81B
+// \82à\82¤\82Ð\82Æ\82Â\82Ì\95û\96@\82Æ\82µ\82Ä\81A\89¹\90º\8fî\95ñ\82ð\82æ\82è\88³\8fk\82µ\83f\81[\83^\97Ê\82ð\8dí\8c¸\82·\82é\95û\96@\82ª\82 \82é\81B
+// \82±\82Ì\95û\96@\82Í\8fã\8bL\82Ì\95û\96@\82ð\8e\8e\82µ\82½\8cã\82É\8ds\82¤\82à\82Ì\82Æ\82·\82é\81B\82Ü\82½\82Í\92¼\90ÚRTP\82ð\8eg\97p\82µ\82½\95û\96@\82ð\8eÀ\91\95\82·\82é\81B
+
+
+// to do
+// \89¹\90º\82Ì\93ü\97Í
+// \89¹\90º\82Ì\8fo\97Í
+// \88³\8fk
+// \89ð\93\9a
+// \83R\83}\83\93\83h\82Ì\93ü\97Í
+// \83T\81[\83o\81[\82Æ\82Ì\92Ê\90M\8b¤\92Ê\8f\88\97\9d
+// \83T\81[\83o\81[\82Ö\82Ì\83\8d\83O\83C\83\93
+// \83T\81[\83o\81[\82Æ\82Ì\83f\81[\83^\82â\82è\8eæ\82è
+
+#include "CClient.h"
+
+#include <iostream>
+
+int main(int argc, char* argv[])
+{
+ char a_LoginName[256];
+ std::cout << "Please, input login name." << std::endl;
+ std::cin >> a_LoginName;
+
+ CClient a_Client;
+ a_Client.initialize();
+ a_Client.setArgement(&argc, argv);
+ a_Client.setLoginName(a_LoginName);
+ a_Client.mainloop();
+
+ return 0;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{B25CF9CE-B08B-4647-A84F-C5B9B13D42AB}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>vc2010_client</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\common\CConnection.cpp" />
+ <ClCompile Include="..\..\common\CSocket.cpp" />
+ <ClCompile Include="..\..\common\CThread.cpp" />
+ <ClCompile Include="CClient.cpp" />
+ <ClCompile Include="CClientModel.cpp" />
+ <ClCompile Include="CClientUI.cpp" />
+ <ClCompile Include="main.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\common\CConnection.h" />
+ <ClInclude Include="..\..\common\CRingBuffer.h" />
+ <ClInclude Include="..\..\common\CSocket.h" />
+ <ClInclude Include="..\..\common\CThread.h" />
+ <ClInclude Include="..\..\common\Data.h" />
+ <ClInclude Include="..\..\common\Environment.h" />
+ <ClInclude Include="CClient.h" />
+ <ClInclude Include="CClientModel.h" />
+ <ClInclude Include="CClientUI.h" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual C++ Express 2010
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vc2010_server", "vc2010_server\vc2010_server.vcxproj", "{31F108CA-4A93-4744-AAA5-BF7E33B595AD}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {31F108CA-4A93-4744-AAA5-BF7E33B595AD}.Debug|Win32.ActiveCfg = Debug|Win32
+ {31F108CA-4A93-4744-AAA5-BF7E33B595AD}.Debug|Win32.Build.0 = Debug|Win32
+ {31F108CA-4A93-4744-AAA5-BF7E33B595AD}.Release|Win32.ActiveCfg = Release|Win32
+ {31F108CA-4A93-4744-AAA5-BF7E33B595AD}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
--- /dev/null
+#include "CServer.h"
+
+#include <iostream>
+
+////////////////////////////////////////////////////////////////////////////////
+// constructor
+////////////////////////////////////////////////////////////////////////////////
+CServer::CServer()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// destructor
+////////////////////////////////////////////////////////////////////////////////
+CServer::~CServer()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// initialize
+////////////////////////////////////////////////////////////////////////////////
+bool CServer::initialize()
+{
+ m_Input.initialize();
+ m_Model.initialize();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// mail loop
+////////////////////////////////////////////////////////////////////////////////
+void CServer::mainloop()
+{
+ // \82Æ\82è\82 \82¦\82¸\96³\8cÀ\83\8b\81[\83v\82É\93ü\82é
+ // q\82Ì\93ü\97Í\82Å\8fI\97¹
+
+
+ std::cout << "start server" << std::endl;
+ std::cout << "input \"END\" to end" << std::endl;
+
+ while(true){
+ if(m_Input.existEvent()){
+ ServerInputEvent a_Event = m_Input.getEvent();
+ if(a_Event == "END"){
+ break;
+ }
+ }
+ m_Model.process();
+ Sleep(1);
+ }
+
+
+ std::cout << "end server" << std::endl;
+}
--- /dev/null
+#ifndef INC_CServer
+#define INC_CServer
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "CServerModel.h"
+#include "CServerInput.h"
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CServer
+////////////////////////////////////////////////////////////////////////////////
+class CServer
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ CServerInput m_Input;
+ CServerModel m_Model;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CServer();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CServer();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8f\89\8aú\89»
+ bool initialize();
+ // main loop
+ void mainloop();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CServer
--- /dev/null
+#include "CServerInput.h"
+
+#include <iostream>
+
+////////////////////////////////////////////////////////////////////////////////
+// constructor
+////////////////////////////////////////////////////////////////////////////////
+CServerInput::CServerInput()
+{
+ m_isEnd = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// destructor
+////////////////////////////////////////////////////////////////////////////////
+CServerInput::~CServerInput()
+{
+ uninitialize();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// start input
+////////////////////////////////////////////////////////////////////////////////
+bool CServerInput::initialize()
+{
+ start();
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// stop input
+////////////////////////////////////////////////////////////////////////////////
+bool CServerInput::uninitialize()
+{
+ m_isEnd = true;
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// thread loop
+////////////////////////////////////////////////////////////////////////////////
+void CServerInput::run()
+{
+ while(true){
+ if(m_isEnd){
+ break;
+ }
+
+ std::string input;
+ std::cin >> input;
+ m_Events.push_back(input);
+ }
+}
--- /dev/null
+#ifndef INC_CServerInput
+#define INC_CServerInput
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "../../common/CThread.h"
+#include <list>
+#include <string>
+
+typedef std::string ServerInputEvent;
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CServerInput
+////////////////////////////////////////////////////////////////////////////////
+class CServerInput : public CThread
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ std::list<ServerInputEvent> m_Events;
+ bool m_isEnd;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CServerInput();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CServerInput();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // start input
+ bool initialize();
+ // stop input
+ bool uninitialize();
+ // thread loop
+ void run();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ServerInputEvent getEvent()
+ {
+ ServerInputEvent temp = m_Events.front();
+ m_Events.pop_front();
+ return temp;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ bool existEvent()
+ {
+ return !m_Events.empty();
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CServerInput
--- /dev/null
+#include "../../common/Environment.h"
+#include "CServerModel.h"
+
+#include <iostream>
+
+////////////////////////////////////////////////////////////////////////////////
+// constructor
+////////////////////////////////////////////////////////////////////////////////
+CServerModel::CServerModel()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// destructor
+////////////////////////////////////////////////////////////////////////////////
+CServerModel::~CServerModel()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// initialize
+////////////////////////////////////////////////////////////////////////////////
+bool CServerModel::initialize()
+{
+ /*
+ m_Connection.initialize();
+ m_Connection.openPort();
+ m_Connection.accept();
+ */
+
+ m_ServerSocket.initialize();
+ m_ServerSocket.openPort();
+ m_ServerSocket.accept(&m_Socket);
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// \8f\88\97\9d
+////////////////////////////////////////////////////////////////////////////////
+bool CServerModel::process()
+{
+ // \92Ê\90M\83N\83\89\83X\82©\82ç\83f\81[\83^\8eæ\93¾
+ CommunicationBuffer* a_pBuffer;
+ //if(m_Connection.getReceiveData(&a_pBuffer)){
+ if(m_Socket.receive(&a_pBuffer)){
+ // \83\8d\83O\83C\83\93\8f\88\97\9d
+ if(a_pBuffer->m_Buffer[0] == 'i'){
+ char a_LoginName[256];
+ // \90³\8bK\95\\8c»\82ð\8eg\82¢\82½\82¢\81i\92N\82©\8eÀ\91\95\82µ\82Ä\82\82¾\82³\82¢\81j
+ for(size_t i = 0; i < 256; i++){
+ if(a_pBuffer->m_Buffer[i + 2] == ';'){
+ a_LoginName[i] = '\0';
+ break;
+ }
+ a_LoginName[i] = a_pBuffer->m_Buffer[i + 2];
+ }
+
+ CommunicationBuffer a_SendBuffer;
+ a_SendBuffer.m_Length = sprintf(a_SendBuffer.m_Buffer, "i:%s;", a_LoginName);
+ m_Connection.setSendData(&a_SendBuffer);
+
+ strcpy(m_AvatarInformation.m_Name, a_LoginName);
+ m_AvatarInformation.m_Position[0] = 0;
+ m_AvatarInformation.m_Position[1] = 0;
+ m_AvatarInformation.m_Position[2] = 0;
+ m_AvatarInformation.m_Direction[0] = 1;
+ m_AvatarInformation.m_Direction[1] = 0;
+ m_AvatarInformation.m_Direction[2] = 0;
+ m_AvatarInformation.m_Radias = 0.3;
+
+ std::cout << "login " << a_LoginName << std::endl;
+ }
+ }
+
+ // \83A\83N\83V\83\87\83\93\83R\83}\83\93\83h\82ð\8f\88\97\9d
+
+ // \89¹\90º\82ð\8d\87\90¬
+
+ // \8eæ\93¾\83R\83}\83\93\83h\82É\91Î\82µ\82Ä\83f\81[\83^\91\97\90M
+ return true;
+}
--- /dev/null
+#ifndef INC_CServerModel
+#define INC_CServerModel
+
+// \83C\83\93\83N\83\8b\81[\83h\82Í\95K\82¸\95K\97v\82È\95¨\82¾\82¯
+// \93à\95\94\82Å\97\98\97p\82·\82é\82¾\82¯\82Ì\95¨\82Í\83\\81[\83X\82É\8bL\8fq
+#include "../../common/Data.h"
+#include "../../common/CConnection.h"
+#include "../../common/CServerSocket.h"
+#include "../../common/CSocket.h"
+
+// \8aÖ\90\94\96¼\82Í\83\8d\81[\83\8f\83L\83\83\83\81\83\8b\83P\81[\83X\82Æ\82·\82é
+
+////////////////////////////////////////////////////////////////////////////////
+// CServerModel
+////////////////////////////////////////////////////////////////////////////////
+class CServerModel
+{
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83\81\83\93\83o\95Ï\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+private:
+ // \83A\83o\83^\81[\8fî\95ñ
+ AvatarInformation m_AvatarInformation;
+ // \92Ê\90M\83N\83\89\83X
+ CConnection m_Connection;
+ // \83T\81[\83o\81[\83\\83P\83b\83g
+ CServerSocket m_ServerSocket;
+ CSocket m_Socket;
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83R\83\93\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ CServerModel();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83f\83X\83g\83\89\83N\83^
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ ~CServerModel();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // static\8aÖ\90\94\81A\83R\81[\83\8b\83o\83b\83N\8aÖ\90\94
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91\80\8dì\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+public:
+ // \8f\89\8aú\89»
+ bool initialize();
+ // \8f\88\97\9d
+ bool process();
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \91®\90«\83\81\83\\83b\83h
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \83C\83e\83\8c\81[\83V\83\87\83\93
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8fó\91Ô
+ ////////////////////////////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // \89\89\8eZ\8eq
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \8f\83\90\88\89¼\91z\8aÖ\90\94\81A\92è\8b`\82Ì\82Ý\81i\94ñ\8eÀ\91\95\92ñ\8b\9f\81j
+ ////////////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////////////
+ // \93à\95\94\83N\83\89\83X
+ ////////////////////////////////////////////////////////////////////////////////
+
+
+};
+
+#endif //INC_CServerModel
--- /dev/null
+// \8b\9e
+#include "../../common/Environment.h"
+
+// library
+#pragma comment(lib, "ws2_32.lib")
+
+
+#include "CServer.h"
+
+int main()
+{
+ CServer a_Server;
+ a_Server.initialize();
+ a_Server.mainloop();
+ return 0;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{31F108CA-4A93-4744-AAA5-BF7E33B595AD}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>vc2010_server</RootNamespace>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="..\..\common\CConnection.cpp" />
+ <ClCompile Include="..\..\common\CServerSocket.cpp" />
+ <ClCompile Include="..\..\common\CSocket.cpp" />
+ <ClCompile Include="..\..\common\CThread.cpp" />
+ <ClCompile Include="CServer.cpp" />
+ <ClCompile Include="CServerInput.cpp" />
+ <ClCompile Include="CServerModel.cpp" />
+ <ClCompile Include="main.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="..\..\common\CConnection.h" />
+ <ClInclude Include="..\..\common\CRingBuffer.h" />
+ <ClInclude Include="..\..\common\CServerSocket.h" />
+ <ClInclude Include="..\..\common\CSocket.h" />
+ <ClInclude Include="..\..\common\CThread.h" />
+ <ClInclude Include="..\..\common\Data.h" />
+ <ClInclude Include="..\..\common\Environment.h" />
+ <ClInclude Include="CServer.h" />
+ <ClInclude Include="CServerInput.h" />
+ <ClInclude Include="CServerModel.h" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file