0

I'm currently develop a client-server application. Let's say I want to find my server ip and port dynamically from client. How would I do that? For IP, let's say I can download and install on server the DUC application from no-ip.com website, and to bind that IP to a well-known site ( let's say www.myserver.biz ), and this site I will use in my client. But in the case of port, what can I do?

Thank you!

charqus
  • 469
  • 1
  • 5
  • 15
  • maybe this question can help: http://stackoverflow.com/questions/4046616/sockets-how-to-find-out-what-port-and-address-im-assigned – RudiDudi Dec 01 '14 at 14:09
  • Nope. I want to find the IP and PORT of the server from client before to connect to the server. It's like I have the IP and PORT stored somewhere on the web, and I query that site and I retrieve those info, and after that I use them. – charqus Dec 01 '14 at 14:14
  • Your comment just said it all. Design a solution that you think might work for you and then work the low-level parts. You can even design a name-server that runs on a specific address (nameserver.example.com) where all the servers register their (IP,port) addresses and all clients query the server for the list of available servers... Use your imagination :) -- Take a look at http://juddi.apache.org – João Neto Dec 01 '14 at 14:32
  • What you normally do is to look up the IP address with DNS and have a fixed port for each protocol (80 for HTTP, 22 for SSH, etc.). If you have a custom protocol you can choose whatever you like unless the server is using that port for some other service. You can have the port number hard coded in the client (or let it be configurable for special cases). – Lars Ljung Dec 01 '14 at 14:37
  • Thank you Lars! How can I hard code the port in the client? – charqus Dec 01 '14 at 14:52

1 Answers1

0

How can I hard code the port in the client?

    struct sockaddr_in servaddr;
    …
    servaddr.sin_port = htons(48484);

But cf. Assigning TCP/IP Ports for In-House Application Use.

Armali
  • 18,255
  • 14
  • 57
  • 171