Results 1 to 8 of 8
  1. #1
    irsalina is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default Attach XML content in UDP socket

    Hai everybody,

    I write a method to send a SIP message to a server by using UDP Socket. The problem arrives when I have to attached an xml file as the Content, the server dont receive the xml file and detect the Content-Length = 0. Thank you for giving me a hint on how to do this in UDP socket. Here is my method:

    public static void sendNotify(){
    final String notifyRequest = "NOTIFY sip:irsa@192.168.1.100:5064 SIP/2.0\r\n"+
    "Via: SIP/2.0/UDP 192.168.1.101:5060;branch=z9hG4bK-393234-a9a4694bf5565e11365831f58ba0b522\r\n"+
    "CSeq: 2 NOTIFY\r\n"+
    "Call-ID: 0ha0isnda977644900765@10.0.0.1\r\n"+
    "From: <sip:alice@open-ims.test>;tag=37d2721c\r\n"+
    "To: <sip:irsa@open-ims.test>;tag=1026\r\n"+
    "Call-ID: 0a11aced29850e7ccea884a679f0d888@192.168.1.100\r\n "+
    "Contact: <sip:192.168.1.101:5060;transport=udp>\r\n"+
    "Route: <sip:mo@scscf.open-ims.test:6060;lr>,<sip:mo@pcscf.open-ims.test:4060;lr>\r\n"+
    "Event: presence\r\n" +
    "Max-Forwards: 70\r\n" +
    "Subscription-State: active;expires=3583\r\n" +
    "Content-Type: application/pidf+xml\r\n" +
    "P-Charging-Vector: icid-value=z9hG4bK-393234-6e5fcdf8a6da1a0c3f2923a42f6608c51308226155111;orig-ioi=mobicents.org\r\n" +
    "Content-Length: 459\r\n"+
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><presence xmlns=\"urn:ietf:params:xml:ns:pidf\" xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\" xmlns:op=\"urn:oma:xml:prs:pidf:oma-pres\" xmlns:opd=\"urn:oma:xml:pde:pidf:ext\" xmlns:rpidf=\"urn:ietf:params:xml:ns:pidf:rpid\" entity=\"sip:alice@open-ims.test\"><tuple id=\"com1\"><status><basic>open</basic></status></tuple><dm:person id=\"per123\"><rpidf:activities id=\"act1\"><rpidf:busy/></rpidf:activities></dm:person></presence> ";

    byte[] notifyRequestBytes = notifyRequest.getBytes();

    try {
    localhost = InetAddress.getByName("10.193.193.46");
    DatagramSocket socket = new DatagramSocket(33276, localhost);
    socket.send(new DatagramPacket(notifyRequestBytes,notifyRequestByt es.length,localhost, 5060));
    } catch (SocketException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    Thank you!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    What code on the server is receiving the Datagram?
    detect the Content-Length = 0
    Where does "Content-Length" come from with Datagrams?

  3. #3
    irsalina is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    I use application server Mobicents (which will receive my Sip message), So, I dont know exactly which code
    I thought Content-Length comes from the length of the xml character/data that I put below the header?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    The string: Content-Length looks like a field in a HTTP request header.
    If you are using Datagrams there wouldn't be a HTTP request header.
    What protocols does your server use at the port you are using? Is it expecting a HTTP request?
    Or does it receive a Datagram?

  5. #5
    irsalina is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    in sip protocol I saw that they use also content-length if I attache an xml. My server listens to UDP in port 5060. It is expecting SIP messages, actually.
    Could you give me some hint?
    Thanks!

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    Sorry, I have no idea what a SIP message is or how a server processes it.
    Google it and see if you are formatting the data correctly.
    Last edited by Norm; 06-21-2011 at 06:29 PM.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default

    Another idea: In HTTP there is a blank line between the header and the data. Does SIP have this? You could need:

    Java Code:
    "Content-Length: 459\r\n\r\n" +

  8. #8
    irsalina is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Another idea: In HTTP there is a blank line between the header and the data. Does SIP have this? You could need:

    Java Code:
    "Content-Length: 459\r\n\r\n" +
    Thank you! It was right, I should put another blank line and it works.

Similar Threads

  1. Replies: 1
    Last Post: 04-19-2011, 08:52 AM
  2. How to attach a listener to a folder
    By bayan in forum New To Java
    Replies: 1
    Last Post: 10-21-2010, 11:03 AM
  3. Attach Photos in SWT to database
    By ashin in forum SWT / JFace
    Replies: 0
    Last Post: 08-09-2010, 06:48 AM
  4. Replies: 4
    Last Post: 03-23-2010, 03:46 PM
  5. how can i attach a worg/image file
    By sniffer139 in forum AWT / Swing
    Replies: 4
    Last Post: 03-12-2010, 06:49 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •