简体   繁体   English

如何在java中发送'SIP请求'(SIP客户端)

[英]How to send ‘SIP request‘ (SIP client) in java

I'm setting up a new client, and want to send SIP request using JAVA. 我正在设置一个新客户端,并希望使用JAVA发送SIP请求。 I have followed some steps but to no avail. 我已经遵循了一些步骤但无济于事。

For example, when sending a request from the client is not given a response from the server ... I think that the HEADER contains errors 例如,当从客户端发送请求时没有从服务器给出响应...我认为HEADER包含错误


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 += "Content-Length: 142";
        Request += "\r\n\r\n";

        socketOutput.print(Request);

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

    }

}

I expect the output will be the response of the server, but the actual no output occurs. 我希望输出将是服务器的响应,但实际没有输出。

Your headers say Content-Length: 142 but you are not sending any content - there is no body to the request. 你的标题说Content-Length: 142但你没有发送任何内容 - 请求没有正文。 So I think that the server is waiting for the 142 bytes of content to arrive before it responds. 所以我认为服务器在响应之前等待142字节的内容到达。 Try setting the content length to zero. 尝试将内容长度设置为零。

(Actually I think you are sending 2 bytes of content because you have a spare \\r\\n at the end, but definitely not 142 bytes) (实际上我认为你发送的是2个字节的内容,因为你最后有一个备用的\\r\\n ,但绝对不是142个字节)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM