0

I'm very new to sockets and SIP but I want to create an SIP application, I'm sure I have enough programming experience, but I just need a push forward to get started.

The problem is I don't get response from a socket, and I just don't know how to debug it. I've created an account at 12connect, and got SIP server login information. Now when I send the 'register' message which we need to start with for a SIP connection it just doesn't do anything. This is the code I use to send the message:

require 'tilt'

module Speaker

  HOST = "**.***.**.**"
  PORT = 5060

  SIP_HOST = "vpbx.12connect.com"
  SIP_USER = "username"
  SIP_PASS = "*********"

  class SIPServer

    def initialize

      EM.connect SIP_HOST, PORT, Speaker::SIPClient

    end

  end

  class SIPClient < EventMachine::Connection

    def post_init

      output = Tilt::ERBTemplate.new('tcp/register.erb').render(template_attributes)
      puts "\nSending: \n#{output}"
      send_data output

    end

    def receive_data data

      puts "From EM Socket: \n"+ data.to_s

    end

    def template_attributes
      {
        host: Speaker::HOST,
        port: Speaker::PORT,

        sip_host: Speaker::SIP_HOST,
        sip_user: Speaker::SIP_USER,
        sip_pass: Speaker::SIP_PASS
      }
    end

  end
end

This is the message that's send:

REGISTER sips:vpbx.12connect.com SIP/2.0
CSeq: 1 REGISTER
Via: SIP/2.0/TCP **.**.**.**:5060
From: <sips:username@vpbx.12connect.com>
To: <sips:username@vpbx.12connect.com>
Contact: <sips:username@**.***.**.**:5060>
Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,SUBSCRIBE,NOTIFY,REFER,MESSAGE,INFO,PING
Expires: 3600
Content-Length: 0
Max-Forwards: 70

I run the application locally and forwarded the 5060 port to the Mac running this app.

EDIT:

What I see in the networking layer is 12 TCP packages from and to port 50206 and 5060. The packages go from my computers local IP to my home IP.. Also there is 1 package from port 50205 to 5060, this package goes from my computers local ip to 193.67.129.180 (vpbx.12connect.com). The 12 must be from the test message I send, and the second is the message stated above..

Another remarkable thing is the 12 packages all go by two, one with a bad checksum and a good one, the rest is the same for each two.

Can anyone tell me I'm missing something here, I tried a lot of different things, but as far as I know this is just the way it needs to be done..?

Thanks in advance!

Tim Baas
  • 6,035
  • 5
  • 45
  • 72
  • 1
    Since you're using TCP the server should be sending its replies down the open socket. Using something like Wireshark, can you see what's happening at the network layer? (But otherwise Juri's right, in the sense that eventually you will have to run a server socket on port 5060 so that you can receive requests.) – Frank Shearar Dec 12 '12 at 10:06
  • I did setup a server for this now, it can receive data on '**.***.**.**:5060', I tested it, and it works. So there must be something wrong in the sending process.. I'll try Wireshark when I get home. Thanks! – Tim Baas Dec 12 '12 at 10:45
  • @FrankShearar I've looked up some specs for the outgoing messages and updated my question, hope you can shine some light on the issue, thanks in advance.. – Tim Baas Dec 12 '12 at 20:28
  • 1
    if you're using Wireshark, it has a mode called something like "follow TCP stream". That will show you the message flows without the noise of the TCP. (For example, it matters little how many TCP packets are involved.) Showing us that output would be most useful! – Frank Shearar Dec 14 '12 at 09:47
  • Tried Wireshark and noticed that the packages weren't acknowleged by the receiver. Turned out the server was UDP only.. Got another IP for TCP now, and sending and receiving messages now works.. Too bad I'm now stuck at another problem, but I'll figure it out.. Thanks for you time anyway! – Tim Baas Dec 14 '12 at 12:17

1 Answers1

0

To establish a connection between two machines, you need two addresses and two ports.

From your code:

  • Server: vpbx.12connect.com:5060
  • Client: **.***.**.**:?

The client port is usually chosen by the operating system, so it is probably not 5060.

Either you somehow get the used client port and also communicate this port in the SIP message, or you open a server on your machine, which you then can bind to a specific port (e.g. 5060).

For SIP I would propose to go with the server approach, since you have to receive messages without connecting to a server before (INVITES).

Juri Glass
  • 88,173
  • 8
  • 33
  • 46
  • Do I understand it right that we have than two socket connections? One client to send data, and a server to receive data? – Tim Baas Dec 11 '12 at 20:18
  • I can't figure this out.. I've setup a server like this: `EM.start_server "0.0.0.0", SIP_PORT, Speaker::SIPReceiver`. The `Contact:` specification should point to my location, and the router should point data to my machine right? Thanks for your help btw! Really appreciatie it! – Tim Baas Dec 11 '12 at 20:29