Esempio n. 1
0
void            Server::run()
{
  ENetEvent     event;

  std::cout << "Actual port => " << _set.getCvar("sv_port") << std::endl;
  std::cout << "Quiet => " << _set.getCvar("sv_quiet") << std::endl;
  std::cout << "Debug => " << _set.getCvar("sv_debug") << std::endl;

  while ((enet_host_service(_server, &event, 50)) >= 0)
    {
      switch (event.type)
        {
        case ENET_EVENT_TYPE_CONNECT:
          connectClient(event.peer);
          break;
        case ENET_EVENT_TYPE_RECEIVE:
          handlePackets(event);
          break;
        case ENET_EVENT_TYPE_DISCONNECT:
          disconnectClient(event.peer);
        default:
          break;
        }
      updateClients();
    }
}
Esempio n. 2
0
void TcpSocket::dataReceived()
{
    while(this->bytesAvailable() > 0) //检查字节数
    {
        char buf[1024];
        int length = bytesAvailable();
        this->read(buf, length); //读取接收
        QString message = buf;
        emit updateClients(message, length); //发射信号
    }
}
Esempio n. 3
0
void TcpSocket::dataReceived()
{
    while(bytesAvailable()>0)
    {
        QByteArray jsonData=readAll();
        jsonFromClient2Server.setJSONData(jsonData);
        jsonFromClient2Server.converJSON2Data();
       protocolFromClient2Server= jsonFromClient2Server.getProtocolFromClient2Server();
        emit updateClients(protocolFromClient2Server);
    }
}
void TcpClientSocket::dataReceived()
{
    while(bytesAvailable()>0)
    {
        int length = bytesAvailable();
        char buf[1024];
        read(buf,length);

        QString msg=buf;
        emit updateClients(msg,length);
    }
}
int TcpClientSocket::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTcpSocket::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: updateClients((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 1: disconnected((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: dataReceived(); break;
        case 3: slotDisconnected(); break;
        default: ;
        }
        _id -= 4;
    }
    return _id;
}