# StreamingSocket and datagram Socket problem

**URL:** https://forum.juce.com/t/streamingsocket-and-datagram-socket-problem/11599
**Category:** General JUCE discussion
**Created:** [October 3, 2013, 9:45am UTC](https://forum.juce.com/t/streamingsocket-and-datagram-socket-problem/11599 "2013-10-03T09:45:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sahilagnihotri](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sahilagnihotri/32/238_2.png) [@sahilagnihotri](https://forum.juce.com/u/sahilagnihotri)
#### Post date: [October 3, 2013, 9:45am UTC](https://forum.juce.com/t/streamingsocket-and-datagram-socket-problem/11599/1 "2013-10-03T09:45:59Z")

</div>

Hey ,&nbsp;

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

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

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScopedPointer\<StreamingSocket\>&nbsp; \_socket = new StreamingSocket();

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\_socket-\>createListener(\_openPort);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\_socket-\>connect("localhost",\_openPort,3000)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;connectionMade = \_socket-\>bindToPort(\_openPort);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(connectionMade == false)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\_openPort++;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; \_socket-\>close();

&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp;

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

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

&nbsp;}

&nbsp;

\_ports is what i pass to webserver .

&nbsp;

//

Sahil

---

<div class="post-metadata">

### Author: ![Bruce\_Wheaton](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Bruce\_Wheaton](https://forum.juce.com/u/Bruce_Wheaton)
#### Post date: [October 8, 2013, 1:39am UTC](https://forum.juce.com/t/streamingsocket-and-datagram-socket-problem/11599/2 "2013-10-08T01:39:13Z")

</div>

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

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![sahilagnihotri](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sahilagnihotri/32/238_2.png) [@sahilagnihotri](https://forum.juce.com/u/sahilagnihotri)
#### Post date: [October 10, 2013, 3:19pm UTC](https://forum.juce.com/t/streamingsocket-and-datagram-socket-problem/11599/3 "2013-10-10T15:19:09Z")

</div>

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.&nbsp;Well in the end had to write native code.

&nbsp;

Sahil

---

<div class="post-metadata">

### Author: ![sambecket](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sambecket/32/1862_2.png) [@sambecket](https://forum.juce.com/u/sambecket)
#### Post date: [October 10, 2013, 10:40pm UTC](https://forum.juce.com/t/streamingsocket-and-datagram-socket-problem/11599/4 "2013-10-10T22:40:13Z")

</div>

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