UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » General
  • » client server program which connects clients with specific IP & Port

#1 2014-10-20 03:23 PM

bsnayak
Member
Registered: 2014-10-20
Posts: 3

client server program which connects clients with specific IP & Port

hello,

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..

Thank you

Offline

#2 2014-10-20 07:53 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: client server program which connects clients with specific IP & Port

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...

Offline

#3 2014-10-21 10:56 AM

bsnayak
Member
Registered: 2014-10-20
Posts: 3

Re: client server program which connects clients with specific IP & Port

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..

Thank you

Offline

#4 2014-10-21 11:08 AM

bsnayak
Member
Registered: 2014-10-20
Posts: 3

Re: client server program which connects clients with specific IP & Port

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 ??

Offline

#5 2014-10-21 12:24 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: client server program which connects clients with specific IP & Port

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...

Offline

  • Index
  • » General
  • » client server program which connects clients with specific IP & Port

Board footer

Powered by FluxBB