bool s13WXWServer::SendString (wxSocketBase *socSocket, std::string strLine) { char *cBuf = new char[(strLine.size () + 1)]; const char *cCopy = strLine.c_str (); for (unsigned int iIdx = 0; iIdx < (strLine.size () + 1); iIdx++) cBuf[iIdx] = cCopy[iIdx]; cBuf[strLine.size ()] = '\0'; //ArrayZero (cBuf, (strLine.size () + 1)); //ArrayCopy (((char *)strLine.c_str ()), cBuf, (strLine.size () + 1)); socSocket->SetNotify (wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); socSocket->Write (cBuf, ((strLine.size () + 1) * sizeof (char))); socSocket->SetNotify (wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); delete []cBuf; cBuf = 0; if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
CServerSocket::~CServerSocket() { // 접속된 소켓은 모두 닫는다. for(long i = 0; i < (long)m_vecpClient.size(); i++) { CloseClientSocket(i); } Close(); }
bool s13WXWServer::SendUChar (wxSocketBase *socSocket, unsigned char ucChar) { socSocket->Write ((const char *)&ucChar, sizeof (unsigned char)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
bool s13WXWServer::SendUShort (wxSocketBase *socSocket, unsigned short usShort) { socSocket->Write ((const char *)&usShort, sizeof (unsigned short)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
bool s13WXWServer::SendULong (wxSocketBase *socSocket, unsigned long ulLong) { socSocket->Write ((const char *)&ulLong, sizeof (unsigned long)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
bool s13WXWServer::SendInt (wxSocketBase *socSocket, int iInt) { socSocket->Write ((const char *)&iInt, sizeof (int)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
bool s13WXWServer::SendDouble (wxSocketBase *socSocket, double dDouble) { socSocket->Write ((const char *)&dDouble, sizeof (double)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
bool s13WXWServer::SendFloat (wxSocketBase *socSocket, float fFloat) { socSocket->Write ((const char *)&fFloat, sizeof (float)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (false); } return (true); }
float s13WXWServer::RecvFloat (wxSocketBase *socSocket) { float fFloat = 0.0f; socSocket->Read ((char *)&fFloat, sizeof (float)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0.0f); } return (fFloat); }
double s13WXWServer::RecvDouble (wxSocketBase *socSocket) { double dDouble = 0.0; socSocket->Read ((char *)&dDouble, sizeof (double)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0.0); } return (dDouble); }
int s13WXWServer::RecvInt (wxSocketBase *socSocket) { int iInt = 0; socSocket->Read ((char *)&iInt, sizeof (int)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (iInt); }
unsigned char s13WXWServer::RecvUChar (wxSocketBase *socSocket) { unsigned char ucChar = 0x00; socSocket->Read ((char *)&ucChar, sizeof (unsigned char)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (ucChar); }
unsigned short s13WXWServer::RecvUShort (wxSocketBase *socSocket) { unsigned short usShort = 0; socSocket->Read ((char *)&usShort, sizeof (unsigned short)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (usShort); }
char s13WXWServer::RecvChar (wxSocketBase *socSocket) { char cChar = 0x00; socSocket->Read ((char *)&cChar, sizeof (char)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (cChar); }
short s13WXWServer::RecvShort (wxSocketBase *socSocket) { short sShort = 0; socSocket->Read ((char *)&sShort, sizeof (short)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (sShort); }
unsigned long s13WXWServer::RecvULong (wxSocketBase *socSocket) { unsigned long ulLong = 0; socSocket->Read ((char *)&ulLong, sizeof (unsigned long)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (ulLong); }
long s13WXWServer::RecvLong (wxSocketBase *socSocket) { long lLong = 0; socSocket->Read ((char *)&lLong, sizeof (long)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (lLong); }
unsigned int s13WXWServer::RecvUInt (wxSocketBase *socSocket) { unsigned int uiInt = 0; socSocket->Read ((char *)&uiInt, sizeof (unsigned int)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (uiInt); }
char *s13WXWServer::RecvString (wxSocketBase *socSocket, int iLength) { char *cString = new char [(iLength + 1)]; //ArraySet (cString, (iLength + 1), '\0'); for (unsigned int iIdx = 0; iIdx < (iLength + 1); iIdx++) cString[iIdx] = '\0'; socSocket->Read (cString, (iLength + 1)); if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (0); } return (cString); }
std::string s13WXWServer::RecvString (wxSocketBase *socSocket) { char *cString = new char [(defNET_MAX_TEXT_SIZE + 1)]; //ArraySet (cString, (defNET_MAX_TEXT_SIZE + 1), '\0'); for (unsigned int iIdx = 0; iIdx < (defNET_MAX_TEXT_SIZE + 1); iIdx++) cString[iIdx] = '\0'; socSocket->Read (cString, defNET_MAX_TEXT_SIZE); std::string strString = cString; delete []cString; cString = 0; if (socSocket->Error () == true) { CloseClientSocket (socSocket); return (""); } return (strString); }
BOOL CIocpServer::Stop() { if(!CheckStoping()) return FALSE; WaitForAcceptThreadEnd(); WaitForWorkerThreadEnd(); CloseClientSocket(); CloseListenSocket(); FireServerShutdown(); ReleaseFreeSocket(); ReleaseFreeBuffer(); CloseCompletePort(); Reset(); m_enState = SS_STOPED; return TRUE; }
/* * Application entry point. */ int main(int argc, char* argv[]) { char *ip = NULL; char *port = NULL; int iResult = 0; system("cls"); // Check input arguments for IP and PORT and open client socket if required if (argc != 3) { printf("Usage: %s <IP> <PORT>\n", argv[0]); printf("EyeX data will not be streamed\n"); } else { ip = argv[1]; port = argv[2]; printf("Trying connection with %s : %s\n", ip, port); clientSocket = OpenClientSocket(ip, port); if (clientSocket == INVALID_SOCKET) { printf("Error at connection with %s : %s\n", ip, port); printf("EyeX data will not be streamed\n"); } else { streaming = TRUE; } } Sleep(2000); TX_CONTEXTHANDLE hContext = TX_EMPTY_HANDLE; TX_TICKET hConnectionStateChangedTicket = TX_INVALID_TICKET; TX_TICKET hEventHandlerTicket = TX_INVALID_TICKET; BOOL success; // initialize and enable the context that is our link to the EyeX Engine. success = txInitializeEyeX(TX_EYEXCOMPONENTOVERRIDEFLAG_NONE, NULL, NULL, NULL, NULL) == TX_RESULT_OK; success &= txCreateContext(&hContext, TX_FALSE) == TX_RESULT_OK; success &= InitializeGlobalInteractorSnapshot(hContext); success &= txRegisterConnectionStateChangedHandler(hContext, &hConnectionStateChangedTicket, OnEngineConnectionStateChanged, NULL) == TX_RESULT_OK; success &= txRegisterEventHandler(hContext, &hEventHandlerTicket, HandleEvent, NULL) == TX_RESULT_OK; success &= txEnableConnection(hContext) == TX_RESULT_OK; // let the events flow until a key is pressed. if (success) { printf("Initialization was successful.\n"); } else { printf("Initialization failed.\n"); } printf("Press X to exit...\n"); _getch(); printf("Exiting.\n"); // disable and delete the context. txDisableConnection(hContext); txReleaseObject(&g_hGlobalInteractorSnapshot); txShutdownContext(hContext, TX_CLEANUPTIMEOUT_DEFAULT, TX_FALSE); txReleaseContext(&hContext); if (streaming) { SendFloatClientSocket(clientSocket, -1); CloseClientSocket(clientSocket); } Beep(300, 750); return 0; }