如何使用PHP或JAVA发送“ SIP请求到服务器IP地址”?

时间:2019-06-20 14:19:12

标签: java php request protocols sip

我正在设置一个新客户端,并想向我的应用程序中的服务器IP地址发送“ SIP请求”。我在PHP,JAVA中尝试了很多次,但是失败了。

例如JAVA,当从客户端发送请求时,服务器未给出响应。

import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class Client
{

    public static void main(String args[]) throws IOException
    {
        Socket socket = new Socket("104.207.221.19", 5060);

        Scanner userInput = new Scanner(System.in);
        Scanner socketInput = new Scanner(socket.getInputStream());

        PrintStream socketOutput = new PrintStream(socket.getOutputStream());

        String Request = "";
        Request = "INVITE sip:bob@domain.com SIP/2.0 \r\n";
        Request += "Via: SIP/2.0/UDP nm;received=51.40.80.23 \r\n";
        Request += "From: <sip:nm@nm>;tag=root \r\n";
        Request += "To: <sip:nm2@nm2>;tag=dff4305d81b6facb \r\n";
        Request += "Call-ID: 50000 \r\n";
        Request += "CSeq: 42 OPTIONS \r\n";
        Request += "Content-Type: application/sdp \r\n";
        Request += "\r\n\r\n";

        socketOutput.print(Request);

        while(socketInput.hasNextLine())
            System.out.println(socketInput.nextLine());
    }
}

在使用(https://github.com/level7systems/php-sip)库的PHP中,当从客户端向服务器IP(67.203.100.10)发送请求时,给我“异常'PhpSIPException',消息为'无法绑定67.203.100.10: 5071请求的地址在其上下文中无效。

try
{
  $api = new PhpSIP('67.203.100.10');  
  $api->setFrom('sip:john@sip.domain.com');
  $api->setUri('sip:anna@sip.domain.com');
  $api->setBody('Hi, can we meet at 5pm   today?');

  $res = $api->send(); 
  echo "res1: $res\n";

  echo "response: $res\n";
} 
catch (Exception $e) 
{
  echo $e;
}

0 个答案:

没有答案