dp198879 2019-06-20 14:19
浏览 316

如何在PHP或JAVA中发送'SIP请求到服务器IP地址'?

I’m setting up a new client, and want to send ‘SIP request’ to server ip address in my application. I tried many times in PHP, JAVA but I failed.

For example JAVA, when sending a request from the client is not given a response from the server.

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 
";
        Request += "Via: SIP/2.0/UDP nm;received=51.40.80.23 
";
        Request += "From: <sip:nm@nm>;tag=root 
";
        Request += "To: <sip:nm2@nm2>;tag=dff4305d81b6facb 
";
        Request += "Call-ID: 50000 
";
        Request += "CSeq: 42 OPTIONS 
";
        Request += "Content-Type: application/sdp 
";
        Request += "

";

        socketOutput.print(Request);

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

And in PHP using (https://github.com/level7systems/php-sip) library, when sending a request from the client to server IP(67.203.100.10), Given to me "exception 'PhpSIPException' with message 'Failed to bind 67.203.100.10:5071 The requested address is not valid in its context".

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
";

  echo "response: $res
";
} 
catch (Exception $e) 
{
  echo $e;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 yolov8边框坐标
    • ¥15 matlab中使用gurobi时报错
    • ¥15 WPF 大屏看板表格背景图片设置
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真