<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 12 (filtered medium)">
<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:12.0pt;
        font-family:"Times New Roman","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.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1873225624;
        mso-list-type:hybrid;
        mso-list-template-ids:1303573676 67698705 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></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"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">This example you mention handles an outbound connection coming FROM FreeSWITCH server. What this means is that your application is *<b>NOT</b>* the one that
 connects to FreeSWITCH, but acts as a server waiting for connections coming from FreeSWITCH. When a call is received on FreeSWITCH, it will open a socket connection to your application and you&#8217;ll have total control of the call.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Please take a couple of minutes and read the wiki page where this is explained: &nbsp;</span><a href="http://wiki.freeswitch.org/wiki/Java_ESL_Client#Outbound_socket_client_usage">http://wiki.freeswitch.org/wiki/Java_ESL_Client#Outbound_socket_client_usage</a><o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">In outbound mode, your code will be executed for every incoming call. If you want to use FreeSWITCH out of the context of an incoming call (like to originate
 new calls) then you must use it in inbound mode (see </span><a href="http://wiki.freeswitch.org/wiki/Java_ESL_Client#Inbound_client_usage">http://wiki.freeswitch.org/wiki/Java_ESL_Client#Inbound_client_usage</a>).
<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">The library contains a very good set of unit tests (ClientTest.java) showing how to use it in inbound mode.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org]
<b>On Behalf Of </b>Marwan Idriss<br>
<b>Sent:</b> Wednesday, April 10, 2013 3:08 AM<br>
<b>To:</b> freeswitch-users@lists.freeswitch.org<br>
<b>Subject:</b> [Freeswitch-users] http://wiki.freeswitch.org/wiki/Java_ESL_Client, how I can make a connection before starting to handle Outbound connection ?<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Greeting,<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">bellow is an example to handle outbound connection and make hung up:<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">but it never show How to make the connection in first place<o:p></o:p></p>
</div>
<p class="MsoNormal">is their an example in main of how this function work ?<o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
/*<br>
&nbsp;* Copyright 2010 david varnes.<br>
&nbsp;*<br>
&nbsp;* Licensed under the Apache License, version 2.0 (the &quot;License&quot;); <br>
&nbsp;* you may not use this file except in compliance with the License. <br>
&nbsp;* You may obtain a copy of the License at:<br>
&nbsp;*<br>
&nbsp;*&nbsp;&nbsp;&nbsp; <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br>
&nbsp;*<br>
&nbsp;* Unless required by applicable law or agreed to in writing, software<br>
&nbsp;* distributed under the License is distributed on an &quot;AS IS&quot; BASIS, <br>
&nbsp;* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
&nbsp;* See the License for the specific language governing permissions and<br>
&nbsp;* limitations under the License.<br>
&nbsp;*/<br>
package org.freeswitch.esl.client.outbound.example;<br>
<br>
import org.freeswitch.esl.client.outbound.AbstractOutboundClientHandler;<br>
import org.freeswitch.esl.client.transport.SendMsg;<br>
import org.freeswitch.esl.client.transport.event.EslEvent;<br>
import org.freeswitch.esl.client.transport.message.EslMessage;<br>
import <a href="http://org.freeswitch.esl.client.transport.message.EslHeaders.Name">
org.freeswitch.esl.client.transport.message.EslHeaders.Name</a>;<br>
import org.jboss.netty.channel.Channel;<br>
import org.jboss.netty.channel.ChannelHandlerContext;<br>
<br>
/**<br>
&nbsp;* Simple example of a handler for outbound connection from FreeSWITCH server.<br>
&nbsp;* This class will log some of the FreeSWTICH call channel variables and <br>
&nbsp;* then hangup the call.&nbsp; <br>
&nbsp;* <br>
&nbsp;* @author&nbsp; david varnes<br>
&nbsp;*/<br>
public class SimpleHangupOutboundHandler extends AbstractOutboundClientHandler<br>
{<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp; protected void handleConnectResponse( ChannelHandlerContext ctx, EslEvent event )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Received connect response [{}]&quot;, event );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( event.getEventName().equalsIgnoreCase( &quot;CHANNEL_DATA&quot; ) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // this is the response to the initial connect <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;=======================&nbsp; incoming channel data&nbsp; =============================&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Event-Date-Local: [{}]&quot;, event.getEventDateLocal() );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Unique-ID: [{}]&quot;, event.getEventHeaders().get( &quot;Unique-ID&quot; ) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Channel-ANI: [{}]&quot;, event.getEventHeaders().get( &quot;Channel-ANI&quot; ) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Answer-State: [{}]&quot;, event.getEventHeaders().get( &quot;Answer-State&quot; ) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Caller-Destination-Number: [{}]&quot;, event.getEventHeaders().get( &quot;Caller-Destination-Number&quot; ) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;=======================&nbsp; = = = = = = = = = = =&nbsp; =============================&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // now hangup the call<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hangupCall( ctx.getChannel() );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new IllegalStateException( &quot;Unexpected event after connect: [&quot; &#43; event.getEventName() &#43; ']' );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp; protected void handleEslEvent( ChannelHandlerContext ctx, EslEvent event )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Received event [{}]&quot;, event );<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; private void hangupCall( Channel channel )<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SendMsg hangupMsg = new SendMsg();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hangupMsg.addCallCommand( &quot;execute&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hangupMsg.addExecuteAppName( &quot;hangup&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EslMessage response = sendSyncMultiLineCommand( channel, hangupMsg.getMsgLines() );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( response.getHeaderValue( Name.REPLY_TEXT ).startsWith( &quot;&#43;OK&quot; ) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://log.info">log.info</a>( &quot;Call hangup successful&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log.error( &quot;Call hangup failed: [{}}&quot;, response.getHeaderValue( Name.REPLY_TEXT ) );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
}<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>