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!
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!
Comment