void Server::listening()
{
	try
	{
		SOCKET hNewClntSock = NULL;
		SOCKADDR_IN clntAdr;
		int addrLen = sizeof( clntAdr );

		if( (hNewClntSock = accept( hServSock, (SOCKADDR*)&clntAdr, &addrLen )) == INVALID_SOCKET )
		{
			if( WSAGetLastError() == WSAEWOULDBLOCK )		// no clients wants to connect
				return;

			else			// error occur while accepting new client
				throw NULL;
		}

		// new client arrived
		Client* newClient = newClientConnected( hNewClntSock, clntAdr );
		CreateIoCompletionPort( (HANDLE)hNewClntSock, hComport, (DWORD)newClient, 0 );

		// invoking recv
		OverlappedIOData* overlappedIOData = new OverlappedIOData();
		DWORD recvBytes = NULL, flags = NULL;
		WSARecv( hNewClntSock, &(overlappedIOData->wsaBuf), 1, &recvBytes, &flags, overlappedIOData, NULL);

	}
	catch(...)		// handle handable exceptions without shutting-down Server
	{
		int a;
		a = 1;
	}
}
示例#2
0
DataBus::Server::Server(QObject *parent)
    : QObject(parent),
      m_tcpServer(parent),
      m_clients()
{
    // Notification of a new connected Client
    connect(&m_tcpServer, SIGNAL(newConnection()), this, SLOT(newClientConnected()));
}
示例#3
0
int MyServer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTcpServer::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: situationChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 1: sendMainWindowMessage((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 2: recivedFromClient((*reinterpret_cast< ClientThread*(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 3: newClientConnected(); break;
        case 4: clientDisconnecting((*reinterpret_cast< ClientThread*(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 5;
    }
    return _id;
}