issues on testing udp chat on same machine

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djsam931
    New Member
    • Mar 2008
    • 2

    issues on testing udp chat on same machine

    hi, im creating a program that allows users to chat using udp sockets..

    as a general description, what i did was fork a child process that sends a udp datagram via an ephemeral port while the parent listens on some specific port..

    to test the program, i am using two different terminals on the same machine..

    when i run the program on one terminal, i set the ip address to 127.0.0.2.. then, i run the same program in another terminal with ip address 127.0.0.1.. so when i send a message to 127.0.0.2 from 127.0.0.1, i indicate 127.0.0.2 as the destination.sin _addr (with the proper conversion of course)..

    the problem is, when the program with ip 127.0.0.2 receives the datagram and i try to display the sender's ip (supposedly 127.0.0.1), it displays 127.0.0.2! the same goes when i send to 127.0.0.1 from 127.0.0.2 : the sender's ip displayed is 127.0.0.1 instead of 127.0.0.2!

    1) is this an issue because i am only using loopback addresses? will this turn out all right when i am running the program on different computers and not using a loopback address?

    2) and also, is there a way to specify on which port i would like to send a message to (and not on some ephemeral port)?

    3) lastly, if i bind some program's, say program 1's, parent's socket (the listener) to an ephemeral port, and program 2's child (the talker) wants to send to program 1, what port will i indicate as the destination port? is there a way to know to what ephemeral port program 1's listener is bound to?

    i dont have enough resources to setup a network so i am only limited to testing on the same machine :(

    thanks a lot!
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by djsam931
    hi, im creating a program that allows users to chat using udp sockets..
    Why use UDP? You're not streaming anything, so TCP would be a much more logical choice. Using UDP you have no receipt-verification process or re-sending of corrupt packets. This means entire chunks of the conversation could be lost without you knowing it.
    Originally posted by djsam931
    as a general description, what i did was fork a child process that sends a udp datagram via an ephemeral port while the parent listens on some specific port..

    to test the program, i am using two different terminals on the same machine..

    when i run the program on one terminal, i set the ip address to 127.0.0.2.. then, i run the same program in another terminal with ip address 127.0.0.1.. so when i send a message to 127.0.0.2 from 127.0.0.1, i indicate 127.0.0.2 as the destination.sin _addr (with the proper conversion of course)..

    the problem is, when the program with ip 127.0.0.2 receives the datagram and i try to display the sender's ip (supposedly 127.0.0.1), it displays 127.0.0.2! the same goes when i send to 127.0.0.1 from 127.0.0.2 : the sender's ip displayed is 127.0.0.1 instead of 127.0.0.2!

    1) is this an issue because i am only using loopback addresses? will this turn out all right when i am running the program on different computers and not using a loopback address?
    Hard to say without seeing your code.
    Originally posted by djsam931
    2) and also, is there a way to specify on which port i would like to send a message to (and not on some ephemeral port)?
    It is possible, but as I haven't done it recently, I'm going to recommend using Google.
    Originally posted by djsam931
    3) lastly, if i bind some program's, say program 1's, parent's socket (the listener) to an ephemeral port, and program 2's child (the talker) wants to send to program 1, what port will i indicate as the destination port? is there a way to know to what ephemeral port program 1's listener is bound to?
    Do you really need to know? Isn't all this stuff handled for you? You could always do a netstat on the machine you're unsure of, but there is also probably an easier way if you were to use the API of the OS this will be running on.
    Originally posted by djsam931
    i dont have enough resources to setup a network so i am only limited to testing on the same machine :(

    thanks a lot!

    Comment

    • djsam931
      New Member
      • Mar 2008
      • 2

      #3
      thanks a lot for the reply.. i'll look into TCP..

      Comment

      Working...