You are not logged in.
Instead of using default client server connection , i want to design specific client based server program, which will first check a specific client 1 with IP1 and port 1 and client 2 with IP2 and port 2 are connected. If both are connected then exchange of information between two clients can be possible..
Kindly suggest, How can i code it..?? possibly share some references which would be helpful..
I'm not really sure what you mean... You're talking about creating a server program which will relay some unspecified information when two specific clients from specific hard-coded IPs and ports connect? What would be the point of that? Backdoor of some sort?
Or, do you just mean when any two clients from any IP and port connect, then the info should be sent to them? What info? Do you mean send the IP of the other client to each one so they can directly connect each other bypassing the server? I hate to say but that probably won't work in most cases due to NATs and firewalls... At least not without some trickery...
I will try to simplify like this..
I have my laptop which i want to run as server. I have two other systems with (IP1, port1, IP2, system2) , which are all connected through UDP connections with eachother. system 1 sends data to server, server modifies the data and sends to system 2.
similarly system 2 sends data to server and server sends the data without modifying to system 1. These datas are hexadecimal coded messages.
But all the codes i checked for multiple clients, they check like this, which is connected first is treated as client1 and the one is second is client 2. How can i specify that client1 must be system1 with specification (IP1, Port1) and client 2 is system 2 with specification (Ip2, port2).
if both are connected the data exchange can take place..
Instead of using default connection type like this
s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
how can i create a socket for specific ip and port.
if my ip is 127.0.0.7 port 1901
how can i create a new socket with this values, what functions needs to be changed ??
Well, if you're using UDP, there really are no "connections" at all... It's a connectionless protocol... So, I assume by who connected first, you just mean the first one to send any message to the server?
If you want the clients to use a specific IP and/or port#, then use bind()... (You can only bind to a valid local IP that corresponds to one of your network interfaces, but you should be free to pick any port# that's not in use...) But, beware: if the clients are behind a NAT box, then it may very well change the values that the server ultimately sees the messages coming from! So, relying on a specific port# to identify the clients isn't really the most reliable approach...
What it sounds like you really want is some form of login/authentication... Have each client provide its ID in the form of a login name and password/key/whatever on their first message to the server... Then, the server will be able to distiguish between them by that name and treat them appropriately...