/*! Finish up * * Clean up * - Sets connectionActive false */ void GdbInOut::finish(void) { Logging::print("GdbInOut::finish()\n"); if (connectionActive) { sendErrorMessage(E_Fatal, "Closing connection"); } connectionActive = false; }
//------------------------------------------------------------------------- static int sendError(sw_socket *s, HTTPError errorCode) { switch(errorCode) { case ERR_BAD_REQUEST: return sendErrorMessage(s, "400", "BadRequest", "400 Bad Request", "Oups, bad request!"); break; case ERR_BAD_METHOD: return sendErrorMessage(s, "501", "MethodNotImplemented", "501 Method Not Implemented", "Oups, method not implemented!"); break; case ERR_UNAVAILABLE: return sendErrorMessage(s, "503", "ServerUnavailable", "503 Server Unavailable", "Oups, server is not available!"); break; case ERR_METHOD_NOT_ALLOWED: return sendErrorMessage(s, "401", "UnauthorizedMethod", "401 Unauthorized Method", "Oups, method is not allowed!"); break; case ERR_HOST_NOT_ALLOWED: return sendErrorMessage(s, "401", "UnauthorizedHost", "401 Unauthorized Host", "Oups, host is not allowed!"); break; case ERR_URL_NOT_ALLOWED: return sendErrorMessage(s, "401", "UnauthorizedURL", "401 Unauthorized URL", "Oups, URL is not allowed!"); break; case ERR_DATE_NOT_ALLOWED: return sendErrorMessage(s, "401", "UnauthorizedDate", "401 Unauthorized Date", "Oups, Date is not allowed!<br>(Document is too old)"); break; case ERR_NOT_FOUND: return sendErrorMessage(s, "404", "NotFound", "404 Not Found", "Oups, File not found"); break; } return -1; }
void SocketController::initConnection() { rootObject = engine.rootObjects().first(); QObject *loginForm = rootObject->findChild<QObject*>("mainLoginForm"); loginTextInput = loginForm->findChild<QObject*>("loginTextInput"); passwordTextInput = loginForm->findChild<QObject*>("passwordTextInput"); hostAddressTextInput = loginForm->findChild<QObject*>("hostAddressTextInput"); if(!socket.doConnect(hostAddressTextInput->property("text").toString(), connectionPort)) sendErrorMessage(socket.getErrorMessage()); }
void ServerClientProxy::update(){ float ifps=0.0f; lock(); ifps=this->newFps; unlock(); if (this->fps!=ifps){ sendErrorMessage(ifps,false,this->sequence); this->fps=ifps; } retrieveFrames(); }
void ServerClientProxy::synchronizeSpeeds(){ if (this->errorQty>=10){ this->fps-=1; lock(); this->newFps=this->fps; unlock(); this->errorQty=0; this->errorWindow=10000; if (this->fps<10){ this->fps=10; } sendErrorMessage(this->fps,false,this->sequence); } }
void HttpConnectionHandler::onRequestArrive(HttpRequestHeader& header, string& body_str) { base::ErrorCode ec; if (sp_stub_dispatcher_) sp_stub_dispatcher_->invokeMethod( boost::static_pointer_cast<HttpConnectionHandler>(this->shared_from_this()), header, body_str, &ec); else ec = base::http::EC_HTTP_SERVICE_INTERNAL_ERROR; if (ec) { sendErrorMessage(header, &ec); LOG(error, "process request (" << header.getPath() << ") failed! " << ec); close(); } }
void SocketController::getValuesFromServer() { connectionLost = false; getGeneralConfigData(); getWifiConfiguration(); accountSettingsLoginTextInput->setProperty("text", getLogin()); getPortTrunkSetup(); getVlanSettings(); corporationInfoText->setProperty("text", getParamInfo("CorporationInfo")); getInfoAboutWifiConnections(); getPortStatusList(); getPortStatusCountersList(); getPortSetupList(); getPoeSetupList(); if (connectionLost) sendErrorMessage(QT_TR_NOOP("connection_lost")); }
/* * Helper function performing the login procedure. */ static void loginHandleSocket(int socket) { // Try to receive the first packet from the client rfc response; int receive = receivePacket(socket, &response); if (receive == -1) { errnoPrint("receive"); return; } else if (receive == 0) { errorPrint("Remote host closed connection"); return; } // Check if we received a login request if (equalLiteral(response.main, "LRQ")) { // Check RFC version if (response.loginRequest.version != RFC_VERSION_NUMBER) { sendErrorMessage(socket, "Login Error: Wrong RFC version used"); infoPrint("Login attempt with wrong RFC version: %d", response.loginRequest.version); return; } // Store username string int length = ntohs(response.main.length) - 1; char s[length + 1]; s[length] = '\0'; memcpy(s, response.loginRequest.name, length); // Check Game Phase if (getGamePhase() != PHASE_PREPARATION) { sendErrorMessage(socket, "Login Error: Game has already started"); infoPrint("Login attempt while game has already started: \"%s\"", s); return; } // Detect empty name string if (length == 0) { sendErrorMessage(socket, "Login Error: A username is required"); infoPrint("Login attempt without a name"); return; } // Detect duplicate names for (int i = 0; i < MAX_PLAYERS; i++) { if (userGetPresent(i)) { if (strcmp(userGetName(i), s) == 0) { sendErrorMessage(socket, "Login error: Name already in use"); infoPrint("Login attempt with duplicate name: \"%s\"", s); return; } } } // Detect too many players int pos = userFirstFreeSlot(); if (pos == -1) { sendErrorMessage(socket, "Login Error: Server is full"); infoPrint("Login attempt while server is full: \"%s\"", s); return; } // Write new user data into "database" userSetPresent(pos, 1); userSetName(pos, s); userSetSocket(pos, socket); scoreMarkForUpdate(); // Start client thread for new user int thread = -1; for (int i = 0; i < (1 + MAX_PLAYERS); i++) { if (threadsFree[i] == -1) { thread = i; } } if (pthread_create(&threads[thread], NULL, clientThread, (void*)pos) != 0) { threadsFree[thread] = pos; errnoPrint("pthread_create"); return; } // Send LOK message response.main.type[0] = 'L'; response.main.type[1] = 'O'; response.main.type[2] = 'K'; response.main.length = htons(2); response.loginResponseOK.version = RFC_VERSION_NUMBER; response.loginResponseOK.clientID = (uint8_t)pos; if (send(socket, &response, RFC_LOK_SIZE, 0) == -1) { errnoPrint("send"); return; } } else { errorPrint("Unexpected response: %c%c%c", response.main.type[0], response.main.type[1], response.main.type[2]); return; } }
int main(int argc, char *argv[]) { int sockfd; struct addrinfo hints, *servinfo, *p; int rv; int numbytes; struct sockaddr_in their_addr; char buf[MAXBUFFLEN]; socklen_t addr_len; char s[INET6_ADDRSTRLEN]; unsigned long ip_in_wait = 0; unsigned short wait_port; /*Check for correct terminal usage for this program. It should be UDPClient Servername Port# requestID hostname1 hostname2 ... hostnameX See assignment paper for details */ if(argc > 2) { fprintf(stderr, "\nusage error: argc = %d\tUDPServer ServerPort#\n", argc); exit(1); } char* serverPort = argv[1]; while (1) { memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; // set to AF_INET to force IPv4 hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_PASSIVE; // use my IP if ((rv = getaddrinfo(NULL, serverPort, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and bind to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("listener: socket"); continue; } if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("listener: bind"); continue; } break; } if (p == NULL) { fprintf(stderr, "listener: failed to bind socket\n"); return 2; } freeaddrinfo(servinfo); printf("\nWaiting for client to connect...\n"); //while (1) { addr_len = sizeof their_addr; if ((numbytes = recvfrom(sockfd, buf, MAXBUFFLEN-1 , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) { perror("recvfrom"); exit(1); } unsigned long ip_address = their_addr.sin_addr.s_addr; if (hasMagicNumber(buf) && isCorrectLength(buf, numbytes) && portIsInRange(buf)) { if(hasClient(ip_in_wait)) { if(sendClientWaitingMessage(buf, ip_in_wait, sockfd, their_addr)) { ip_in_wait = 0; } else { perror("listener: sendto"); exit(1); } } else { //Removed second paramter: their_addr.sin_port //Need to just grab the client's port within the request AlexAg if (sendNoClientMessage(buf, sockfd, their_addr)) { ip_in_wait = 1; } else { perror("listener: sendto"); exit(1); } ip_in_wait = ip_address; wait_port = their_addr.sin_port; } } else { sendErrorMessage(buf, sockfd, p, numbytes); } close(sockfd); } return 0; }
void SerialCommunication::receiveStopSignalFromHardware() { char * complete = "stop"; bool fContinue = true; do { // Wait for an event lLastError = serial.WaitEvent(); if (lLastError != ERROR_SUCCESS) emit sendErrorMessage(serial.GetLastError(), "Unable to wait for a COM-port event."); // Save event const CSerial::EEvent eEvent = serial.GetEventType(); // Handle break event if (eEvent & CSerial::EEventBreak) { printf("\n### BREAK received ###\n"); } // Handle error event if (eEvent & CSerial::EEventError) { QString message; message.append("Error occured while scanning.\nError Type: "); switch (serial.GetError()) { case CSerial::EErrorBreak: message.append("Break condition"); break; case CSerial::EErrorFrame: message.append("Framing error"); break; case CSerial::EErrorIOE: message.append("IO device error"); break; case CSerial::EErrorMode: message.append("Unsupported mode"); break; case CSerial::EErrorOverrun: message.append("Buffer overrun"); break; case CSerial::EErrorRxOver: message.append("Input buffer overflow"); break; case CSerial::EErrorParity: message.append("Input parity error"); break; case CSerial::EErrorTxFull: message.append("Output buffer full"); break; default: message.append("Unknown Error"); break; } emit sendErrorMessage(serial.GetLastError(), message.toLocal8Bit().data()); } // Handle data receive event if (eEvent & CSerial::EEventRecv) { // Read data, until there is nothing left DWORD dwBytesRead = 0; char szBuffer[10]; do { // Read data from the COM-port lLastError = serial.Read(szBuffer,sizeof(szBuffer)-1,&dwBytesRead); if (lLastError != ERROR_SUCCESS) emit sendErrorMessage(serial.GetLastError(), "Unable to read from COM-port."); if (dwBytesRead > 0) { // Finalize the data, so it is a valid string szBuffer[dwBytesRead] = '\0'; // Check for Stop Text //if(strstr(szBuffer, complete) != NULL) fContinue = false; mutex.lock(); isScanComplete = true; mutex.unlock(); } } while (dwBytesRead == sizeof(szBuffer)-1); } } while (fContinue); // Close the port again serial.Close(); }