Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things to be aware of using your suggested architecture:</p> <p><a href="https://stackoverflow.com/questions/285290/trying-to-send-an-http-request-over-sockets">Trying to send an HTTP request over sockets</a></p> <p>Principally, you need to be aware that even though you can chat http at a lower level using sockets, there are a large number of cases where communication in this fashion will fail. Mainly these failures will occur if the user has a proxy server enabled in their browser, as there is no effective means of discovering and subsequently using the proxy when connecting via a socket.</p> <p>In order to make a policy server, you can use the <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx" rel="nofollow noreferrer">TcpListener</a> class. You would start listening as follows:</p> <pre><code>var tcpListener = new TcpListener(IPAddress.Any, 843 ); tcpListener.start(); tcpListener.BeginAcceptTcpClient(new AsyncCallback(NewClientHandler), null); </code></pre> <p>The method NewClientHandler would have the form:</p> <pre><code> private void NewClientHandler(IAsyncResult ar) { TcpClient tcpClient = tcpListener.EndAcceptTcpClient(ar); ... </code></pre> <p>At which point you might want to supply the tcpClient object to a class of your own creation to handle the validation of the data coming from the socket. I'm going to call it RemoteClient.</p> <p>In RemoteClient, you'd have something like this:</p> <pre><code> var buffer=new byte[BUFFER_SIZE]; tcpClient.GetStream().BeginRead(buffer, 0, buffer.Length, Receive, null); </code></pre> <p>and a Receive method:</p> <pre><code> private void Receive(IAsyncResult ar) { int bytesRead; try { bytesRead = tcpClient.GetStream().EndRead(ar); } catch (Exception e) { //something bad happened. Cleanup required return; } if (bytesRead != 0) { char[] charBuffer = utf8Encoding.GetChars(buffer, 0, bytesRead); try { tcpClient.GetStream().BeginRead(buffer, 0, buffer.Length, Receive, null); } catch (Exception e) { //something bad happened. Cleanup required } } else { //socket closed, I think? return; } } </code></pre> <p>and some send methods:</p> <pre><code> public void Send(XmlDocument doc) { Send(doc.OuterXml); } private void Send(String str) { Byte[] sendBuf = utf8Encoding.GetBytes(str); Send(sendBuf); } private void Send(Byte[] sendBuf) { try { tcpClient.GetStream().Write(sendBuf, 0, sendBuf.Length); tcpClient.GetStream().WriteByte(0); tcpClient.GetStream().WriteByte(13); //very important to terminate XmlSocket data in this way, otherwise Flash can't read it. } catch (Exception e) { //something bad happened. cleanup? return; } } </code></pre> <p>That's all the important details I think. I wrote this some time ago... the Receive method looks like it could do with a rework, but it should be enough to get you started.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload