int FtpClient::Login() { try { char buffer[2048]; int code; strcpy ( buffer, "USER " ); strcat ( buffer, this->userName ); if(!SendMessage ( buffer )) { perror("Can't send message\n"); return 1; } strcpy ( buffer, ReceiveMessage() ); //receiving confirmation code = GetCode ( buffer ); if ( code != 331 ) //if the FTP server sent a code that it's not 331, than we've got problems return code; strcpy ( buffer, "PASS " ); strcat ( buffer, password ); SendMessage ( buffer ); //now we have to send the password strcpy ( buffer, ReceiveMessage() ); code = GetCode ( buffer ); Sock = _Socket; if ( code != 230 ) //if something went wrong, then we send the code back to the calling function return code; } catch ( Exception ex ) { cout << ex.Message; } return 0; //this means that we are logged in }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t2_instance(void) { StatusType result_inst_1, result_inst_2, result_inst_3, result_inst_4, result_inst_5; StatusType received_char; SCHEDULING_CHECK_INIT(11); result_inst_1 = GetMessageStatus(rm); SCHEDULING_CHECK_AND_EQUAL_INT(13,E_COM_ID, result_inst_1); SCHEDULING_CHECK_INIT(14); result_inst_2 = ReceiveMessage(rm, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(14,E_OK, result_inst_2); SCHEDULING_CHECK_AND_EQUAL_INT(14,(int)('1'), (int)received_char); SCHEDULING_CHECK_INIT(15); result_inst_3 = ReceiveMessage(rm, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(15,E_OK, result_inst_3); SCHEDULING_CHECK_AND_EQUAL_INT(15,(int)('1'), (int)received_char); SCHEDULING_CHECK_INIT(16); result_inst_4 = ReceiveMessage(INVALID_MESSAGE, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT(19,E_COM_ID, result_inst_4); SCHEDULING_CHECK_INIT(20); result_inst_5 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(20,E_OK, result_inst_5); }
//this_ui_add_start bool CUIPointInitDlg::OnKeyPress(int iKey) { switch(iKey) { case DIK_RETURN: ReceiveMessage(m_pBtn_Ok, UIMSG_BUTTON_CLICK); return true; case DIK_ESCAPE: ReceiveMessage(m_pBtn_Cancel, UIMSG_BUTTON_CLICK); return true; } return CN3UIBase::OnKeyPress(iKey); }
bool CUIWarp::OnKeyPress(int iKey) { switch(iKey) { case SDL_SCANCODE_ESCAPE://DIK_ESCAPE: ReceiveMessage(m_pBtn_Cancel, UIMSG_BUTTON_CLICK); return true; case SDL_SCANCODE_RETURN://DIK_RETURN: ReceiveMessage(m_pBtn_Ok, UIMSG_BUTTON_CLICK); return true; } return CN3UIBase::OnKeyPress(iKey); }
int MsgQueueConnection::recv(uint num_bytes, char *dest, uint /*non_blocking_read_ahead*/) { if (!is_connected()) { LOG("SKYPE ERROR - LocalServerConnection::recv(), not connected"); return -1; } uint nBytesRead = 0; while (nBytesRead < num_bytes) { if (m_iReadIndex >= m_cBuffer.len) { if (ReceiveMessage() == false) return -1; m_iReadIndex = 0; } uint n = min((uint)m_cBuffer.len - m_iReadIndex, num_bytes-nBytesRead); Mem::Copy(dest, m_cBuffer.msg+m_iReadIndex, n); m_iReadIndex += n; nBytesRead += n; } return nBytesRead; }
void ProcessWriteFile(int sock, std::string pathFile,size_t offset,std::string buffer) { std::cout << "ProcessWriteFile \n"; std::stringstream ss; ss << WRITEFILE_REQUEST << pathFile << "," << offset << "," << buffer; Message mesToSend, mesToReceive; mesToSend.typeMes = Text; mesToSend.content = ss.str(); mesToSend.sizeMes = mesToSend.content.size(); std::cout << "send - " << mesToSend.content << std::endl; SendMessage(sock, mesToSend); /* Receiving result read file */ ReceiveMessage(sock, mesToReceive); if (mesToReceive.typeMes != Binary) { std::cout << "Server invalid \n"; return; } ResultCode rc = (ResultCode)(*(BYTE*)mesToReceive.content.data()); if (rc == Success) { std::cout << "Success \n"; } else { std::cout << "Fail \n"; } }
void ProcessGetListEntry(int sock, std::string pathDir) { std::cout << "ProcessGetListEntry \n"; Message mesToSend, mesToReceive; mesToSend.typeMes = Text; mesToSend.content = GETLISTENTRY_REQUEST + pathDir; mesToSend.sizeMes = mesToSend.content.size(); std::cout << "send - " << mesToSend.content << std::endl; SendMessage(sock, mesToSend); ReceiveMessage(sock,mesToReceive); if (mesToReceive.typeMes != Text) { std::cout << "Server invalid (1).\n"; return; } std::cout << mesToReceive.content << std::endl; std::vector<std::string> array_str; int numberEntry = Split(mesToReceive.content, array_str, ";"); if (numberEntry > 0) { for (int i = 0; i < numberEntry; i++) { std::vector<std::string> entry_type; int size = Split(array_str[i],entry_type,"="); if (size == 2) { std::cout << entry_type[0] << " is " << entry_type[1] << std::endl; } } } }
char *FtpClient::GetCurrentDirectory() { try { char buffer[2048]; bzero ( buffer, 2048 ); SendMessage ( "PWD" ); strcpy ( buffer, ReceiveMessage() ); int code = GetCode ( buffer ); if ( code == 257 ) { int i = 0; for ( i = 0; i < strlen ( buffer ) && buffer[i] != '\"'; i++ ); char dir[2048]; bzero ( dir, 2048 ); strcpy ( dir, buffer + ( i + 1 ) ); for ( i = 0; i < strlen ( dir ) && dir[i] != '\"'; i++ ); dir[i] = '\0'; return dir; } else return "error"; } catch ( Exception ex ) { cout << ex.Message; return ex.Message; } }
void War2Wiz::Receive ( JBroadcaster* sender, const Message& message ) { if (message.Is(JMessageProtocolT::kMessageReady)) { JIndex senderIndex; WarSocket* socket = GetSender(sender, &senderIndex); ReceiveMessage(senderIndex, *socket); } else if (message.Is(JMessageProtocolT::kReceivedDisconnect)) { ReceiveDisconnect(sender, kJFalse); } else if (message.Is(WarSocket::kTimeout)) { ReceiveDisconnect(sender, kJTrue); } else { JBroadcaster::Receive(sender, message); } }
void receiveRequests() { // service ready klog("spawner server ready"); // defining size for messages const size_t requestLenMax = sizeof(MessageHeader) + sizeof(SpawnCommandSpawnRequest) + 1024; while (true) { // creating buffer for message uint8_t requestBuffer[requestLenMax]; // receive incoming request MessageReceiveStatus stat = ReceiveMessage(requestBuffer, requestLenMax); if (stat != MESSAGE_RECEIVE_STATUS_SUCCESSFUL) protocolError("receiving command failed with code %i", stat); MessageHeader *header = (MessageHeader*) requestBuffer; SpawnCommandHeader *commandHeader = (SpawnCommandHeader*) MESSAGE_CONTENT(header); if (commandHeader->command == SPAWN_COMMAND_SPAWN_REQUEST) processSpawnRequest((SpawnCommandSpawnRequest*) commandHeader, header->sender, header->transaction); else if (commandHeader->command == SPAWN_COMMAND_SHUTDOWN_MACHINE || commandHeader->command == SPAWN_COMMAND_REBOOT_MACHINE) processHealtMachine(commandHeader->command); else protocolError("received unknown command: code %i, task %i", commandHeader->command, header->sender); } }
void CommThread :: HandleMessage( Message * pcMessage ) { switch( pcMessage->GetCode() ) { case MSG_TOLOOPER_START: { SendReceiveLoop(); break; } case MSG_TOLOOPER_RECEIVE: { ReceiveMessage(); break; } case MSG_TOLOOPER_SEND: { SendMessage(); break; } default: Looper::HandleMessage( pcMessage ); break; } }
bool SendTransaction::RequestId() { QByteArray fileData; MakeFileData(fileData); if (!TransmitMessage(State::Request::REQUEST_PERMISSION, fileData)) { emit TransmissionFailed(State::Error::ID_RECEIVING_FAILED); return false; } Message msg; if (!ReceiveMessage(msg)) { emit TransmissionFailed(State::Error::ID_RECEIVING_FAILED); return false; } if (msg.state == State::Response::TRANSMISSION_DECLINED) { emit TransmissionCancelled(); return false; } if (msg.state != State::Response::RESP_ID) { emit TransmissionFailed(State::Error::ID_RECEIVING_FAILED); return false; } MakePeerData(msg, addr_, port_); id_ = msg.id; return true; }
bool CUILogIn::ReceiveMessage(CN3UIBase* pSender, DWORD dwMsg) { if(NULL == pSender) return false; //s_CameraData.vp; //불러 오는 과정을 살펴본다 //DWORD mm = s_CameraData.vp.Height; //DWORD ss = s_CameraData.vp.Width; if (dwMsg == UIMSG_BUTTON_CLICK) { if (pSender == m_pBtn_LogIn && m_pEdit_id && m_pEdit_pw) { CGameProcedure::s_pProcLogIn->MsgSend_AccountLogIn(LIC_KNIGHTONLINE); } else if(pSender == m_pBtn_Connect) { CGameProcedure::s_pProcLogIn->ConnectToGameServer(); // 고른 게임 서버에 접속 } else if (pSender == m_pBtn_Cancel) { //PostQuitMessage(0); // 종료... CGameBase::s_bRunning = false; } else if(pSender == m_pBtn_Option) // 옵션.. { std::string szMsg; szMsg = "Would you like to open the options?";//::_LoadStringFromResource(IDS_CONFIRM_EXECUTE_OPTION, szMsg); CGameProcedure::MessageBoxPost(szMsg, "", MB_YESNO, BEHAVIOR_EXECUTE_OPTION); } } else if(UIMSG_LIST_DBLCLK == dwMsg) { CGameProcedure::s_pProcLogIn->ConnectToGameServer(); // 고른 게임 서버에 접속 } else if (dwMsg == UIMSG_EDIT_RETURN) { // TEMP(srmeier): there is a weird issue where the key inputs aren't going // through CGameProcedure::ProcessUIKeyInput() so CUILogIn::OnKeyPress() isn't // being called... if(!m_bLogIn && m_pEdit_id && m_pEdit_pw) { CN3UIBase* pMsgBox = CGameProcedure::s_pMsgBoxMgr->GetFocusMsgBox(); if( !(pMsgBox && pMsgBox->IsVisible()) ) CGameProcedure::s_pProcLogIn->MsgSend_AccountLogIn(LIC_KNIGHTONLINE); } else { ReceiveMessage(m_pBtn_Connect, UIMSG_BUTTON_CLICK); } } else if (dwMsg == UIMSG_EDIT_TAB) { // TEMP(srmeier): there is a weird issue where the key inputs aren't going // through CGameProcedure::ProcessUIKeyInput() so CUILogIn::OnKeyPress() isn't // being called... FocusCircular(); } return true; }
void Aggregator::ClearMessageQueue() { myDPID from; DWORD BufferLen; char* Buffer; while (ReceiveMessage(Buffer,BufferLen,from)==DP_OK) {} }
//====================================================== // Send a message to a message port and wait for a reply //====================================================== void SendReceiveMessage(struct MessagePort *MP, struct Message *Msg) { struct MessagePort *tempMP = AllocMessagePort(); Msg->tempPort = tempMP; SendMessage(MP, Msg); ReceiveMessage(tempMP, Msg); DeallocMem(tempMP); }
internal void * ReceiveMessageAndAck(volatile mailbox *Mailbox) { void *Result = ReceiveMessage(Mailbox); AckMessage(Mailbox); return Result; }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t2_instance(void) { StatusType result_inst_1; StatusType received_char; SCHEDULING_CHECK_INIT(10); result_inst_1 = ReceiveMessage(rm_activatetask, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(10,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(10,(int)('1'), (int)received_char); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_comcallback_instance(void) { StatusType result_inst_1; StatusType received_char; /*not allowed !!! Should be E_OS_CALLEVEL*/ SCHEDULING_CHECK_INIT(10); result_inst_1 = ReceiveMessage(rm_comcallback, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(10,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(10,(int)('3'), (int)received_char); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t5_instance2(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(26); result_inst_1 = ReceiveMessage(rm_newislessorequal, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(26,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(26,1, (int)received_char); SCHEDULING_CHECK_INIT(27); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(27,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t6_instance1(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(6); result_inst_1 = ReceiveMessage(rm_maskednewequalsmaskedold, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(6,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(6,3, (int)received_char); SCHEDULING_CHECK_INIT(7); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(7,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t2_instance3(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(31); result_inst_1 = ReceiveMessage(rm_maskednewequalsx, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(31,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(31,7, (int)received_char); SCHEDULING_CHECK_INIT(32); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(32,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t4_instance1(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(16); result_inst_1 = ReceiveMessage(rm_newisgreater, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(16,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(16,3, (int)received_char); SCHEDULING_CHECK_INIT(17); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(17,E_OK, result_inst_2); }
bool CUIQuestTalk::OnKeyPress(int iKey) { switch(iKey) { case SDL_SCANCODE_ESCAPE://DIK_ESCAPE: SetVisible(false); return true; case SDL_SCANCODE_RETURN://DIK_RETURN: ReceiveMessage(m_pBtnOk, UIMSG_BUTTON_CLICK); return true; } return CN3UIBase::OnKeyPress(iKey); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t5_instance3(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(22); result_inst_1 = ReceiveMessage(rm_newisdifferent, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(22,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(22,7, (int)received_char); SCHEDULING_CHECK_INIT(23); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(23,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t2_instance8(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(43); result_inst_1 = ReceiveMessage(rm_always, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(43,2, (int)received_char); SCHEDULING_CHECK_AND_EQUAL_INT(43,E_OK, result_inst_1); SCHEDULING_CHECK_INIT(44); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(44,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t8_instance3(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(61); result_inst_1 = ReceiveMessage(rm_oneeveryn, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(61,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(61,5, (int)received_char); SCHEDULING_CHECK_INIT(62); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(62,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t2_instance(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(4); result_inst_1 = ReceiveMessage(rm_activatetask, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(4,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(4,(int)('1'), (int)received_char); SCHEDULING_CHECK_INIT(5); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(5,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t7_instance2(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(18); result_inst_1 = ReceiveMessage(rm_newisgreaterorequal, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(18,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(18,3, (int)received_char); SCHEDULING_CHECK_INIT(19); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(19,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t6_instance2(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(41); result_inst_1 = ReceiveMessage(rm_newisless, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(41,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(41,0, (int)received_char); SCHEDULING_CHECK_INIT(42); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(42,E_OK, result_inst_2); }
/*test case:test the reaction of the system called with an activation of a task*/ static void test_t7_instance2(void) { StatusType result_inst_1, result_inst_2; StatusType received_char; SCHEDULING_CHECK_INIT(45); result_inst_1 = ReceiveMessage(rm_maskednewdiffersmaskedold, &received_char); SCHEDULING_CHECK_AND_EQUAL_INT_FIRST(45,E_OK, result_inst_1); SCHEDULING_CHECK_AND_EQUAL_INT(45,2, (int)received_char); SCHEDULING_CHECK_INIT(46); result_inst_2 = TerminateTask(); SCHEDULING_CHECK_AND_EQUAL_INT(46,E_OK, result_inst_2); }