How to send a packet through a specific Inferface ?

Hello!
I have 3 interfaces in my pc : LAN / WLAN / 3G
On LAN I have a global IP.
On WLAN and 3G I'm behind NAT.
I'm coding a program (client+srv) >
I watch a video streaming on LAN then I switch to WLAN or 3G and I want it to happen seamless. So basecly seamless vertical handover is my goal.
Because I'm behind a NAT (3G,WLAN) First I have to send a packet to the server (connection initialization). When the server sends the stream to me it actually sends it to the NAT and the NAT will fwd it to me.
The NAT send the packets back to me only if>
1. the server sends from the same port which it received the request form the NAT
2. It have to send to the same NAT (ip+port) address where the request came from
3. NAT will send then the packet back to my PC to the same port where I sent my request from.
Here comes my big problem!
I have a socket bound to a IP1 and port (e.g. WLAN) if I want to send a packet to an destination IPx for which the route table has the LAN interface as default gateway (IP2), then it will send my packet trough the LAN (IP2) but the source IP will be IP1 in the packet.
Basecly I have a WLAN package on my LAN.
This is bad for me in 2 ways.
1. there won't be a NAT binding for my WLAN
2. the packet won't even make it to the server because the very first router will throw it away since it's source IP is not a LAN IP
SO,
is there a way in Java, to send a packet thorugh a specific interface???
Thx for the kind help!
r0hamkuka

I used NetworkInterface.getNetworkInterfaces() to get all avaliable interfaces. After that I used this: interfaceSocket = new DatagramSocket(6000, interfaceIp); for all my interfaces with different interfaceIp of course
The I tried to send a packet to 153.66.200.155 for example (LAN address) through my WLAN interface (ip for example: 192.168.1.101) using WLAN's interfaceSocket.send()
But the packet goes out on my LAN interface (ip 153.66.200.166) while the src ip is still 192.168.1.101 in the packet. That is why I sad WLAN packet on LAN interface.
I guess the reason is still the routing table. Because routing table tells which IF to use for a destination IP. Of course for dest 153.66.x.x routing table contains 153.66.200.166 as the gateway and not 192.168.1.101. So Win uses this the LAN IF to send the packet.

Similar Messages

  • How to send RTP packet through SIP Dialog

    Hello there !
    I work on a Java softphone which use JMF and Jain-SIP. I know JMF is "old" but I think it would be simple to capture and transmit RTP audio. So, my SIP dialog is working, I can send text messages but now, I would like to send RTP with this SIP session. I know I have to send SDP messages for codec convenience but then, what is the MediaLocator for RTP packet ? Only SIP User Agent IP or something else ?
    I also accept all ressources that can help me achieve my work :)

    I have no idea how SIP works, but, RTP packets go to an IP:PORT... theoretically, in the SIP phonecall setup, I'd imagine you'd have to be given the address to send RTP packets to the remote phone. Or perhaps the port is already well-defined by the SIP standard.
    Either way, you should have a way of knowing / finding out which PORT to send to for your SIP call, either from the call setup or the SIP standard itself.

  • How to send image file through mail without   any attachment

    Plz tell  me how to send image file through mail without any attachment  ( i mean not converting  that image into pdf or any format )  i want to send that text or image  through mail .

    Hi Sandeep,
    I think you can setup the type of email in Shared office Settings in transaction S016.
    There is an option called <Preset document classes>
    You choose this pushbutton to branch to the maintenance screen for the document classes that are directly displayed to users in the Business Workplace for selection when they use the Create function. The name under which the documents are displayed can also be maintained.
    http://help.sap.com/saphelp_nw70/helpdata/en/6c/69c30f418d11d1896e0000e8322d00/content.htm
    Haven't tried it though.
    Regards,
    Siddhesh

  • How to send a mail through web dynpro application

    Hi
    How to send a mail through web dynpro application?
    Thanks

    Hi ,
      Please post some more details about your query .
    One way is to can use LinkToUrl UI element and in the reference property of the UI element , give it as mailto:mail addess
    Thanks.
    aditya.

  • Make a Cisco SPA 303 ring by sending a packet through your network?

    Hey Guys,
    I was wondering, and I need to know for my business, is there any way at all for me to make my Cisco SPA 303 VOIP Phone to ring by sending a packet through my local network?
    I would like to just be able to click a button or send a command throught the command prompt and make it ring, but I don't know if there is any way for this to happen.
    Thank!

    Do you know perl?
    I had same issue and I wrote a simple perl script that works as wake up service.
    PERL is an interpreted language and so can be executed on Linux and  Windows operating systems. Linux can interpret perl natively while for  Windows you can download many free interpreters like Activeperl or  Strawberry perl. To run the script you must use a third party server.
    In my configuration the script runs on a linux server in background as a service and checks every minute the  directory called "alarm", reads files and uses the file name as called  number and checks the content to verify if is the time to call. At the moment the script uses SIP and handles 4 call responses: 404 user  not found, 486 busy, 487 not answer and 200 answer ok.  In every cases sends an email and deletes files. Only for the answer  case plays a nice music.
    Files have this particular format: file name is equal to calling  party number and file content is the alarm time in 24 hours format  with : as separator between hours and minutes.
    e.g.
    ext. 101 must be called at 8 am ---> write the file 101.txt with the content 08:00
    ext. 101 must be called at 8:30 am ---> write the file 101.txt with the content 08:30
    There is a limitation: if you activate the Authentication for SIP messages and there are more  then two simultaneous calls, the script sends some INVITEs without  authentication or with wrong checksum and so not all phones ring. This  problem is under investigation.
    Are you intresting?
    Regards.

  • How can I play music through safari specifically youtube on my Mac book pro over soundlink to my bose wireless speaker I can only play audio from itunes at present? HELP PLEASE!

    How can I play music through safari specifically youtube on my Mac book pro over soundlink to my bose wireless speaker I can only play audio from itunes at present? HELP PLEASE!

    Should be able to go into your sound preferences and choose your output device, you can also try downloading Airfoil and try that, it's a pretty cool app.

  • How to send a sms through froms6i..........

    Can nyone tell me how to send sms through forms6i....................its urgent................

    hey there are many companies giving sms power to you...
    so you can do one thing just make the code below in your button trigger
    and supply the required parameters...
    host('C:\Program Files\Internet Explorer\IEXPLORE.exe http:\\www.'||:IE);
    and then :IE is one of text field there you can write som thing like below...
    http://<your service provider website name and path > ?outLogin=<login>&outPWD=<password>&outMSG=<sms_msg>&outNumber=<phone number>&sign=<signature>
    you have to replace <param name> and make appropriate changes...
    one website i know is....."http://timessms.com"
    Enjoy Oracle....
    Message was edited by:
    Ravi Suthar

  • How to send sales orders through XI  to non sap system

    Hello Experts,
    i need to send Sales order details from ECC to non sap system.
    anybody can help me to proceed with this in detailed way.
    i know how to send idoc through xi between sap systems.
    But i need between sap to non sap system.
    Thanks & Regards,
    Lakshmi..

    Hi !!
    Check this weblog on how to enable SSL:
    /people/gregor.wolf3/blog/2005/10/11/setup-https-ssl-for-the-sneak-preview-sap-netweaver-04-abap-edition-on-windows
    refer this realtive thread which shows the .NETnet integration with XI
    Re: .NET Client Integration with SAP XI
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2131 [original link is broken] [original link is broken] [original link is broken]
    for idoc related settings in r/3 refer the below link...
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/73527b2c-0501-0010-5398-c4ac372c9692
    IDoc to File scenario
    /people/prateek.shah/blog/2005/06/08/introduction-to-idoc-xi-file-scenario-and-complete-walk-through-for-starters
    check this out ..
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFAALEQS/CABFAALEQS.pdf
    http://www.thespot4sap.com/Articles/SAP_ALE_Introduction.asp
    Also go thru this Blogs
    ALE Configuration for Pushing IDOC's from SAP to XI by Swaroopa Vishwanath
    Configuration Steps for Posting IDOC's by Ravikumar Allampalam.
    IDOC - File scenario
    /people/prateek.shah/blog/2005/06/08/introduction-to-idoc-xi-file-scenario-and-complete-walk-through-for-starters
    configuring IDOCS
    /people/sravya.talanki2/blog/2006/12/27/aspirant-to-learn-sap-xiyou-won-the-jackpot-if-you-read-this-part-iii
    IDOC scenarios
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cdded790-0201-0010-6db8-beb9bb2b2660
    Idoc related setting
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/73527b2c-0501-0010-5398-c4ac372c9692
    refer this thread also
    Integration between sap and non-sap
    /people/prateek.shah/blog/2005/06/08/introduction-to-idoc-xi-file-scenario-and-complete-walk-through-for-starters
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5651.. [original link is broken] [original link is broken] [original link is broken]
    also referthe concept of SSO
    To undersand SSO scenarios gothro the links in my reply in the following thread:
    SSO scenarios and configuring steps
    Check the following link to know the procedure for user mapping:
    Procedure to follow for user mapping.
    The following link gives you more idea on User Mapping:
    More Info on User Mapping
    Pls reward if useful

  • How to send entire dashbord through agents in 111g

    Hi,
    I have to trigger entire dashboard to to concern person. But i am able to select only page under dashboard, we have multiple dashboards and send all those through agents.
    Please let me know how to achieve it
    Regards,
    Ma

    yes..you can can send only Dashboard page not the entire dashboard....

  • How to send PDF attachment through Email For Purchase Order

    Hi,
         Can you please tell me how to send the Purchase Order with PDF attachment. Thank you.
    Thanks & Regards,
    Rani.

    Find the below example
    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Write statement to represent report output. Spool request is created
    if write statement is executed in background. This could also be an
    ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    Alternative way could be to submit another program and store spool
    id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
           to sap-spool
           spool parameters   %_print
           archive parameters %_print
           without spool dynpro
           and return.
    Get spool id from program called above
    IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
          FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
          FORM get_job_details                                          *
    FORM get_job_details.
    Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
          FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid              = gd_spool_nr
                no_dialog                = c_no
                dst_device               = c_device
           IMPORTING
                pdf_bytecount            = gd_bytecount
           TABLES
                pdf                      = it_pdf_output
           EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11
                OTHERS                   = 12.
      CHECK sy-subrc = 0.
    Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
          FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    perform send_email using p_email2.
    ENDFORM.
          FORM send_email                                               *
    -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
          FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    Reward if helpful.
    Thanks,
    Kishore S N

  • How to send my report through e-mail

    Hello to All
    i am generating a report in report 2.5 what i want in place of sending report to printer or screen i want to send reports output through email either in html or pdf format.
    please send me the solution for the same.
    thanks.
    null

    Hello to All
    i am generating a report in report 2.5 what i want in place of sending report to printer or screen i want to send reports output through email either in html or pdf format.
    please send me the solution for the same.
    thanks.
    null

  • How to send Html Mail through navigateToUrl() with contentType "text/html" for Android ?

    Isn't it possible to send Html Mail through navigateToUrl() with contentType "text/html" for Android ? please suggest any workaround
    Thanks

    AHHHH
    What you can do to make HTML for Apple Mail is to make it in an HTML editor, open it with Safari use CMD+i - a new mail message will appear in a moment with the web page in the email body.
    You can't do any major editing in Mail, you'll have to go back to the HTML file. But it works.
    You can also use Copy (from a web page) and then (Edit) Paste as HTML (that what Paste as HTML is for, not for creating HTML email). You can also user Paste as HTML to copy/paste a HTML email you receive or part of a HTML email.

  • How to send smartform output through email

    Hi,
    I want to send smartform output through email.....
    can u give me sample program to send it through email......
    Regards,
    Jenifer
    MOderator Message: Basic and Frequently asked question. Please search before posting.
    Edited by: kishan P on Nov 26, 2010 11:11 AM

    Hi Jenifer,
    There are many threads available on SDN.
    Just have a look at this thread
    <<link removed by moderator>>
    Kindly search before you post.
    Regard
    Abhii
    Moderator Message: You have been warned many times against point-hunting. Continuing ignoring of the Moderator warnings will lead to account deletion. Consider this your last warning
    Edited by: kishan P on Nov 26, 2010 11:09 AM

  • How to send a packet to multiple recipients?

    I'm writing a small chat program in java. What I have so far for the server, is this:
    import java.io.*;
    public class datagramServer {
         public static void main(String[] args) throws IOException {
              new datagramServerThread().start();
    }datagramServerThread class:
    import java.net.*;
    import java.util.*;
    import java.io.*;
    public class datagramServerThread extends Thread {
        protected DatagramSocket socket = null;
        boolean listening = true;
        datagramProtocol DGP = new datagramProtocol();
        public datagramServerThread() throws IOException {
         this("datagramServerThread");
        public datagramServerThread(String name) throws IOException {
            super(name);
            socket = new DatagramSocket(4445);
        public void run() {
            while (listening) {
                try {
                    byte[] buf = new byte[256];
                    DatagramPacket packet = new DatagramPacket(buf, buf.length);
                    socket.receive(packet);
                    String processSendBack = new String(packet.getData());
                    String sendBack = DGP.processInput(processSendBack);
                    buf = sendBack.getBytes();
                    InetAddress address = packet.getAddress();
                    int port = packet.getPort();
                    packet = new DatagramPacket(buf, buf.length, address, port);
                    socket.send(packet);
                catch (IOException e) {
                    e.printStackTrace();
            socket.close();
    }And the datagramProtocol class:
    import java.io.*;
    import java.net.*;
    public class datagramProtocol {
         String output;
         public String processInput(String toProcess) {
              output = toProcess;
              return output;
    }Pretty simple, and it works great, if you just want to chat with yourself... ;)
    The client is really simple, just sends and receives, nothing fancy.
    What I want to know, is how would I send anything any client sends, to every other connected client?
    btw, I was wondering if it's good coding practice to put everything into a seperate class like that. I probably could've put everything into one, but it's a little neater in seperate files.
    Thanks,
    Alex

    Can a publish/subscribe sort of model be used in it's
    place? Or how about just a listener model rather
    than pushing each request? This way the clients just
    register themselves and listeners and you merely
    propogate an event. There would be no need to keep
    track of each IP, etc.
    Just thinking out loud here... :)Well, as I understand, on a publish/subscriber model, the publisher has to keep some sort of reference to the listener in order to send the events when they happen.
    Keeping the sockets to the clients seems to me as good as a reference can be on a TCP/IP connection short of using RMI to do that, but if the client/server must be decoupled from the language what I sugested is a publish/subscriber model. The clients are the subscribers, they ad themselves as such upon connecting to the server, the server wich is the publisher store their reference as subscribers by keeping the socket where they agreed upon communicating.
    When the publisher has a new message to be published it walks the list of references giving them the event, wich is the message posted.
    Sure it could be done with events just notifying the arrival of new messages but it would just complicate the model beyond the need. For the client would have to wait for the event and them send a request asking for the actual message, in order to do such a system he would have to create a simple protocol of comunication between the client and the server.
    May the code be with you.

  • How to send a link for a specific podcast file?

    So I'm in my Podcasts directory in iTunes 5.0 and I've got a bunch of downloaded podcasts. Just listened to a particular one that I really like and I'd like to send a link for that podcast to a friend. How to get the link? I do a Get Info on the file and there's no URL anywhere.
    Even if I manually add a podcast by choosing "Subscribe to podcast" from the Advanced menu, then entering the podcast URL, if I thereafter try to retrieve that URL from somewhere in the downloaded podcast, it's nowhere to be found. Surely I'm missing something obvious. Now there are a very few podcasts that seem to put that info in their "Show Description" (aka the "Podcast Information" window) but they're the exception.
    Before you suggest control-clicking in the iTunes Music Store and choosing "Copy iTunes Music Store URL," note that that doesn't get close to the mark at all, and besides, I need to do this for podcasts that aren't on the iTunes Music Store. Thanks!

    I should probably give an actual example to make myself clear. When you refer to clicking the "i," note that doing that is what I was talking about when I wrote: "there are a very few podcasts that seem to put that info in their 'Show Description' (aka the 'Podcast Information' window) but they're the exception." In other words, clicking the "i" opens the Podcast Information window. Same window opens if you choose "Show Description" from the contextual menu that opens when you control-click on the feed name.
    But the URL that appears in the Podcast Information window (besides not being selectable for copying and also being in a window that disappears if you switch apps), is just the link to the RSS page that lists ALL the episodes. It is not a link to a specific episode. What I want is the ability FROM A DOWNLOADED PODCAST EPISODE to extract the link for that specific episode. I guess this would be equivalent to clicking the "Get" button next to a dimmed episode that has not yet been downloaded, though I don't really care that clicking that link (if I could find it) wouldn't automatically download the episode into iTunes for the person to whom I would send the link.
    So, for example, the link that I can extract from the KCRW On the Beat podcast is this:
    feed://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/podcastRSS?id =73331691
    But what I want is to get the link (from within iTunes, not by visiting the web page) of the "Our Pop Stars Lead Us" episode, which is here:
    http://66.186.18.80/podcast/mp3/ob/ob050907Afterthe_DelugeOur.mp3
    See what I mean?

Maybe you are looking for