I'm setting up a new client, and want to send SIP request using JAVA. 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
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. So I think that the server is waiting for the 142 bytes of content to arrive before it responds. 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.