<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
code
{mso-style-priority:99;
font-family:"Courier New";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal">I hope someone can help me here as I have been stuck for the past 3 days.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">I need to allow a client to connect to a websocket running on server 10.0.4.160 on port 8080.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">I need to setup a secure tunnel to allow the client to connect to the websocket via port 58443.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">I installed the latest version of stunnel on my windows Server 2008 R2. Then I changed my stunnel.conf file
to look like this <o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">[websockets]<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">client = yes<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">accept = 58443<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">connect = 8080<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">verify = 2<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">checkIP = 10.0.4.195<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">CAfile = ca-certs.pem<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">debug = 7<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">OCSPaia = yes
<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">##The rest have been removed<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">I am expecting to open a connection from the user’s console on port 58443 and the stunnel will allow the client
to connect to port 8080<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">This is the code that I use in the client's console "Of course, the console is on a PC that is on my internal
network"<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">var conn = new WebSocket('wss://10.0.4.160:58443');<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">conn.onopen = function(e) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0"> console.log("Connection established!");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">};<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">conn.onmessage = function(e) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0"> console.log(e.data);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New";color:#7030A0">};<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">While on the server, I open up a command line and I execute this
<b><u><span style="color:#7030A0">telnet localhost 8080</span></u></b><span style="color:#7030A0">
</span>to open up a command line where I can see the incoming request. As soon as I fire the code above from a client javascript’s console I see this in the server's command line<o:p></o:p></span></p>
<p class="MsoNormal"><img width="628" height="313" id="Picture_x0020_1" src="cid:image001.png@01D0D8E6.8F1CC750"><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p>But few seconds later I get this error in the client’s console<o:p></o:p></p>
<pre><code>WebSocket connection to 'wss://10.0.4.160:58443/' failed: Error in connection establishment: net::ERR_TIMED_OUT<o:p></o:p></code></pre>
<p>If I try to send a command using <code><span style="font-size:10.0pt">conn.sent('Hello')</span></code> I get this error<o:p></o:p></p>
<pre><code><span style="color:red">VM289:2 Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.<o:p></o:p></span></code></pre>
<pre><code><span style="color:red"> at Error (native)<o:p></o:p></span></code></pre>
<pre><code><span style="color:red"> at <anonymous>:2:6<o:p></o:p></span></code></pre>
<pre><code><span style="color:red"> at Object.InjectedScript._evaluateOn (<anonymous>:905:140)<o:p></o:p></span></code></pre>
<pre><code><span style="color:red"> at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)<o:p></o:p></span></code></pre>
<pre><code><span style="color:red"> at Object.InjectedScript.evaluate (<anonymous>:694:21)<o:p></o:p></span></code></pre>
<p>Additionally, I tried to turn on debugging in strunnel by adding <code><span style="font-size:10.0pt;color:#7030A0">debug = 7</span></code><code><span style="font-size:10.0pt"> to the config file</span></code><o:p></o:p></p>
<p>This is what I got in the stunnel console. I don't understand what is wrong as the logs show that the client is connected but I can't send messages from the client to the server<o:p></o:p></p>
<pre><code>2015.08.16 16:40:06 LOG7[36]: Service [websockets] started<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG5[36]: Service [websockets] accepted connection from 10.0.4.195:21963<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG6[36]: s_connect: connecting 127.0.0.1:8080<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG7[36]: s_connect: s_poll_wait 127.0.0.1:8080: waiting 10 seconds<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG5[36]: s_connect: connected 127.0.0.1:8080<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG5[36]: Service [websockets] connected remote server from 127.0.0.1:50891<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG7[36]: Remote socket (FD=668) initialized<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG6[36]: SNI: sending servername: localhost<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG7[36]: SSL state (connect): before/connect initialization<o:p></o:p></code></pre>
<pre><code>2015.08.16 16:40:06 LOG7[36]: SSL state (connect): SSLv2/v3 write client hello A<o:p></o:p></code></pre>
<p>What am I doing wrong here? How come the connection keeps failing?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>