StreamingSocket and datagram Socket problem

Hey , 

I am creating an application using juce with embedded webserver , so i am scanning for open ports on machine and launch webserver on it. I am doing this but doesnt seem to be working :


        bool connectionMade = false;
        while (( !connectionMade) && (_openPort < 65535))
        {  

          ScopedPointer<StreamingSocket>  _socket = new StreamingSocket();

         _socket->createListener(_openPort);

          _socket->connect("localhost",_openPort,3000)

          connectionMade = _socket->bindToPort(_openPort);

          if(connectionMade == false)

                 _openPort++;

           _socket->close();

 

        }

 

Also tried using the UDP same problem , it returns false connect or bind, using the latest libraries:


while (( !connectionMade) && (_openPort < 65535))
    {      
            ScopedPointer<DatagramSocket>    _socket = new DatagramSocket(_openPort,false);
           _socket->isLocal();
            //    ScopedPointer<DatagramSocket> _socket = new DatagramSocket(_openPort); // chcekingfor open port
            //_openPort = _socket->getPort();
           bool connectionMade = _socket->isConnected();
            if(!connectionMade)
                _openPort++;
           _socket->close();
            _ports = String(_openPort);

 }

 

_ports is what i pass to webserver .

 

//

Sahil

What port number are you trying? Ports below 1024 have permissions problems. If you haven't already, try above 1024. 8080 is a common 'alternate webserver port' for this reason.

By the way, don't those function get stuck in infinite loops? Don't you mean 'if' not 'when' at the start of each?

bruce

 

 

I was trying above 1024 till 65535, The reason for searching open ports was in case the 8080 is acquired by some other webserver as i have embedded webserver in application . So was scaning port if its already occupied then use diff , else thsi one. Well in the end had to write native code.

 

Sahil

Your scopedpointer is deleting your new StreamingSocket() every loop recursion, i can use websockets, but i must initiate them, and let them be... not killing them every loop !