theintencity / php-sip

Automatically exported from code.google.com/p/php-sip
3 stars 1 forks source link

port in use error - workaround provided #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am unsure if this is really a bug or the way it is supposed to be so I did 
not look for a code change.  If you try to send multiple packets on the same 
instance php-sip will try to rebind to send the additional ones and will fail.  

It feels like a bug to me, in that I should be able to send multiple packets on 
a single instance. My gut tells me that a check to see if the socket is already 
bound should be performed and only attempt to bind() if it has not previously 
been set up.  I realize that this can be tricky if there is not good tracking 
of sessions, which response goes to what packet sent.

To work around this limitation I unset() the instance in my loop, which causes 
more code to be executed than otherwise should be (everything in the 
destructor/constructor plus the socket related operations).

What steps will reproduce the problem?
1. see code below

What version of the product are you using? On what operating system?
current as of April 18, 2011 - linux

Please provide any additional information below.

while(SOME_CONDITION) {
    $sip = new PhpSIP();
    // additional setup instructions redacted
    $res = $sip->send(); //  this blocks for a single response
                         //  when placing a call you may get multiple
                         //  responses (200, 183, etc)
    unset($sip);  // this works around the binding problem
}

Original issue reported on code.google.com by trixter%...@gtempaccount.com on 20 Apr 2011 at 9:36

GoogleCodeExporter commented 9 years ago
Actually you can send multiple packet on a single instance, however need to 
slightly change your loop:

$sip = new PhpSIP();

while(SOME_CONDITION) {

    // additional setup instructions redacted
    $res = $sip->send(); //  this blocks for a single response
                         //  when placing a call you may get multiple
                         //  responses (200, 183, etc)
    // still the same "call" (dialog) set another URI, Method etc. do more stuff...
    $res = $sip->send();

    // new "call" - reset Call-ID, To/From tags
    $sip->newCall();

    // set new URI, SIP method etc.
    $res = $sip->send();
}

Original comment by level7systems@googlemail.com on 20 Apr 2011 at 9:43

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I will try with the newCall() method.  When I had the constructor outside the 
loop I got the port in use error, I only moved it inside the loop for the 
workaround.

Original comment by trixter%...@gtempaccount.com on 20 Apr 2011 at 10:20