Example #1
0
/*
 * This method has two functionalities
 * -It waits for incoming connections if local port is defined
 * -It tries to connect to remote host if local host is not defined
 */
void IPCommMonitorThread::Connect(Socket*& s)
{
	// This trickery here is because if there are no sockets (Socket::nofSockets_)
	// WSACleanup gets called and then SOAP gets messed up.
	// And creating a new socket for a new connection seems to work better
	// than using the old when re-connecting / re-listening.
	Socket* new_s = new Socket();
	delete s;
	s = new_s;

	// If local port is defined start open listening socket
	SocketServer ss;
	if( m_LocalPort )
	{
		Util::Info("[IPComm] Listen for incoming connection...");
		String remoteHost( "[IPComm] Connected! Remote host : " );
		ss.Accept( s, m_LocalPort, 1, remoteHost );
		Util::Info(remoteHost);
	}
	// If not start connecting
	else
	{
		Util::Info("[IPComm] Connecting...");
		ss.Connect( s, m_RemoteHost.c_str(), m_RemotePort );
		Util::Info("[IPComm] Connected!");
	}
}
Example #2
0
int main(void)
{
    try
    {
        std::vector<DylThread*> vectorOfThreads;
        SocketServer servSock = SocketServer (2000);
        while (1) 
        {
            std::cout << "I am a server!" << std::endl;

            //create a new socket
            
            Socket s = servSock.Accept(); // blocking call - waits for request

            //put that new socket into a thread
            DylThread *dThr =  new DylThread(s, true);
            vectorOfThreads.push_back(dThr);

            std::cout << "hm +" << vectorOfThreads << std::endl;

          for (DylThread* i: vectorOfThreads)
              {
                std::cout << "hm " << i << std::endl;
              }

        }




    }


    // catch(...)
    catch(std::string e)
    {
        std::cout << e << " Caught unexpected exception" << std::endl;
    }
}