<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.4.2">
</HEAD>
<BODY>
Hi Klaus,<BR>
<BR>
Thanks but it doesn't do what I need.&nbsp; That function closes the connection after the next send by setting SND_F_CON_CLOSE (which is the what the tcpconn_close_after_send() macro in tcp_conn.h does too).<BR>
<BR>
Unfortunately, I need to be able to cleanly close a connection immediately without any further sends.<BR>
<BR>
Thanks,<BR>
<BR>
Peter<BR>
<BR>
On Mon, 2012-06-18 at 12:01 +0200, Klaus Darilion wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
See how this function works:

<A HREF="http://www.kamailio.org/dokuwiki/doku.php/core-cookbook:3.1.x#set_forward_close">http://www.kamailio.org/dokuwiki/doku.php/core-cookbook:3.1.x#set_forward_close</A>

It might help you

On 17.06.2012 15:11, Peter Dunkley wrote:
&gt; Hi,
&gt;
&gt; One of the things I need to be able to do from the WebSocket module is to
&gt; cleanly close TCP/TLS connections when I receive/send a Close() frame.
&gt;
&gt; Is there an easy way to do this from a Kamailio module?
&gt;
&gt; Regards,
&gt;
&gt; Peter
&gt;
&gt;&gt; Hello,
&gt;&gt;
&gt;&gt; On 6/15/12 11:33 AM, Peter Dunkley wrote:
&gt;&gt;&gt; Hi Daniel,
&gt;&gt;&gt;
&gt;&gt;&gt; Thanks for the encouragement.
&gt;&gt;&gt;
&gt;&gt;&gt; I could do with a guide here.  I think there is only a few hours work
&gt;&gt;&gt; left to finish off the handshake and basic module stuff. After that I
&gt;&gt;&gt; think the next step needs to be:
&gt;&gt;&gt; - Getting the module to register with core to receive WS frames (which
&gt;&gt;&gt; may arrive over TCP or TLS)
&gt;&gt;&gt; - Giving the module/core the ability to &quot;change&quot; the connection the
&gt;&gt;&gt; handshake came in on from SIP/HTTP to WS (so that new messages go
&gt;&gt;&gt; straight to the handler in the new module)
&gt;&gt;&gt; - In the module adding handling for Close, Ping, and Pong
&gt;&gt;&gt; - To do the handling for Ping the module needs to be able to send WS
&gt;&gt;&gt; frames out (over TCP or TLS)
&gt;&gt;&gt; - In the module &quot;printing&quot; received binary and text frames (which will
&gt;&gt;&gt; contain SIP requests)
&gt;&gt;&gt;
&gt;&gt;&gt; The bits I need help with here the most are the registering the module
&gt;&gt;&gt; to receive the WS frames and sending WS frames (over TCP or TLS), and
&gt;&gt;&gt; adding the ability for the module/core to &quot;upgrade&quot; the connection
&gt;&gt;&gt; from SIP/HTTP to WS after successful handshake.
&gt;&gt;
&gt;&gt; I think of doing it like:
&gt;&gt; - when WS handshake is completed, mark the tcp connection as being WS
&gt;&gt; from the module (a new flag or so)
&gt;&gt; - then in the TCP read function (iirc, tcp_read.{c,h} in core) if the
&gt;&gt; connection is marked WS, then execute a callback that is registered by
&gt;&gt; the module
&gt;&gt; - this is pretty much how http and msrp work, but there the detection is
&gt;&gt; on the content, not on the socket type. HTTP is using so called no-SIP
&gt;&gt; content callback, while MSRP is using a dedicated core event
&gt;&gt;
&gt;&gt; For sending, using tcp_send(...) (looking at msrp module will give the
&gt;&gt; right directions) should do it -- the function takes the tcp connection
&gt;&gt; as parameter as well as the outgoing buffer and encrypts the content if
&gt;&gt; actually is over TLS. The send operation may become transparent as soon
&gt;&gt; as the algorithm for finding the connection can grep on WS/WSS protocol.
&gt;&gt;
&gt;&gt; Cheers,
&gt;&gt; Daniel
&gt;&gt;
&gt;&gt;&gt;
&gt;&gt; --
&gt;&gt; Daniel-Constantin Mierla - <A HREF="http://www.asipto.com">http://www.asipto.com</A>
&gt;&gt; <A HREF="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</A> - <A HREF="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</A>
&gt;&gt; Kamailio Advanced Training, Seattle, USA, Sep 23-26, 2012 -
&gt;&gt; <A HREF="http://asipto.com/u/katu">http://asipto.com/u/katu</A>
&gt;&gt; Kamailio Practical Workshop, Netherlands, Sep 10-12, 2012 -
&gt;&gt; <A HREF="http://asipto.com/u/kpw">http://asipto.com/u/kpw</A>
&gt;&gt;
&gt;&gt;
&gt;
&gt;
</PRE>
</BLOCKQUOTE>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>
-- 
Peter Dunkley
Technical Director
Crocodile RCS Ltd
</PRE>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>