[Freeswitch-users] Possible to communicate with FS using event_socket without ESL?

Bert Jones rmbertjones at comcast.net
Thu Feb 17 17:36:51 MSK 2011


Hi Again Steve,

 

This is resolved now.  It appears that I was not doing the initiation and
authentication with the proper number of linefeeds and with the proper
sequence of writes AND reads.  For those interested, here is a working
function written in vb.net to do the communications on the localhost
machine.  The assumption is made that the password has been changed from
ClueCon to myPassword in modules.config.xml and that mod_event_socket is
loaded in modules.conf.xml  using the entry: <load
module="mod_event_socket"/>.

 

Thanks to all for the help. 

Bert

 

 

  Function SendCommands_socket(ByVal id, ByVal Cmnd)

            'Funciton to initiate conneciton with FreeSWITCH event_socket
via a tcpsocket, authenticate and send a command.

            'Note that the writes AND reads are all mandatory, as are the
double linefeeds.

 

            'Dims

            Dim returndata As String = "" 'Holds return data

            Dim sendBytes As [Byte]() ' byte array used to hold outbound
data after conversion from ascii to byte array

            Dim tcpClient As New System.Net.Sockets.TcpClient() ' the tcp
socket client used to communicate with the host

            Dim rcvBytes(tcpClient.ReceiveBufferSize) As Byte 'byte array
used to receive bytes returned from host

 

            Try

                'Initiate conneciton with event_socket via the
socket--------------------

                tcpClient.Connect("localhost", 8021)

                Dim stream As NetworkStream = tcpClient.GetStream() 'open
the socket

                stream.Read(rcvBytes, 0, CInt(tcpClient.ReceiveBufferSize))

                returndata = Encoding.ASCII.GetString(rcvBytes)

                MsgBox(returndata) 'should say "Content-Type: auth/request"

 

                If stream.CanWrite And stream.CanRead Then

                    'Do
authentication.-------------------------------------------------

                    ' convert text to byte array

                    sendBytes = Encoding.ASCII.GetBytes("auth myPassword" &
vbCrLf & vbCrLf) '(The 2 crlf are mandatory )

                    ' write data to stream

                    stream.Write(sendBytes, 0, sendBytes.Length)

                    ' read the NetworkStream into a seperate byte buffer. 

                    stream.Read(rcvBytes, 0,
CInt(tcpClient.ReceiveBufferSize))

                    ' convert binary bytes received into ascii

                    returndata = Encoding.ASCII.GetString(rcvBytes)

                    MsgBox(returndata) 'should say "Content-Type:
command/reply Reply-Text: +Ok accepted"

 

                    'Send the
command.-------------------------------------------------

                    sendBytes = Encoding.ASCII.GetBytes(Cmnd & vbCrLf &
vbCrLf)

                    stream.Write(sendBytes, 0, sendBytes.Length)

                    stream.Read(rcvBytes, 0,
CInt(tcpClient.ReceiveBufferSize))

                    returndata = Encoding.ASCII.GetString(rcvBytes)

                    MsgBox(returndata)

                Else

                    If Not stream.CanRead Then

                        Console.WriteLine("cannot not write data to this
stream")

                        tcpClient.Close()

                    Else

                        If Not stream.CanWrite Then

                            Console.WriteLine("cannot read data from this
stream")

                            tcpClient.Close()

                        End If

                    End If

                End If

 

                ' Disconnect

                tcpClient.Close()

 

                Return returndata

 

            Catch oEX As SocketException

                ' Disconnect

                tcpClient.Close()

                Return oEX.ToString

                Exit Function

            End Try

 

        End Function

 

From: freeswitch-users-bounces at lists.freeswitch.org
[mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Bert
Jones
Sent: Sunday, February 13, 2011 11:41 PM
To: 'FreeSWITCH Users Help'
Subject: Re: [Freeswitch-users] Possible to communicate with FS using
event_socket without ESL?

 

Thanks for the clarification.  I too suspect something in my communications.
Just wanted to make sure I was not missing something. Will move my
communication app to a separate machine from the FS server and run
Wireshark.  Thanks for recommendation.

Bert

 

From: freeswitch-users-bounces at lists.freeswitch.org
[mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Steven
Ayre
Sent: Sunday, February 13, 2011 7:29 AM
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] Possible to communicate with FS using
event_socket without ESL?

 

Without the use of the ESL *protocol* - no. Without the use of the supplied
ESL *libraries* - correct.

You're along the right lines on implementing your own protocol. If you can
connect and authenticate via telnet from the same computer you're trying
your app from then there should be no problem with FS.

The fact you say it takes 10s for FS to respond indicates you're not sending
the auth line. You should get either a success or failure message straight
away in reply to that. So it sounds like the auth isn't getting sent at all.

Try using Wireshark to view what's going over the network to check it's what
you expect.

-Steve






On 13 February 2011 03:27, Bert Jones <rmbertjones at comcast.net> wrote:

Hello,

 

Am I correct in assuming that an app can talk directly to FS using
event_socket without the use of the ESL?  I am attempting to do this, but
having trouble authenticating. I wanted to make sure I was not overlooking
something basis in my approach.

 

I have successfully loaded FS on a windows XP server and can register phones
and make calls.  Further I can talk to the server, authenticate and make
calls using telnet, but when attempting to do the same via an app written in
.net and using a socket, I am unable to authenticate.  

 

Running my app using a tcpSocket, I receive the "Content-Type: auth/request"
upon connection of the socket, but when sending "auth password\n\n" it
appears that the connection times out after about 10 seconds and I receive:
"Content-Type: text/disconnect-notice" & vbLf & "Content-Length: 67".
mod_event_socket is enabled in modules.conf.xml .

 

Is there something obvious that I am missing conceptually, or should this
work?

 

Thanks!

 

 

 

 


_______________________________________________
FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20110217/8274be86/attachment-0001.html 


More information about the FreeSWITCH-users mailing list