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 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型
    • ¥15 求学软件的前人们指明方向🥺
    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn