Find the answer to your Linux question:
Results 1 to 2 of 2
Hi to everyone, I'm Alejandro from Argentina. I'm programming a client/server application for the University and my problem is that i make it function in a local network, but i ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    1

    Socket problems

    Hi to everyone, I'm Alejandro from Argentina. I'm programming a client/server application for the University and my problem is that i make it function in a local network, but i don't understand how to make it work accross internet. I don't have a public ip so if i puy the serer in my computer and the client in my friend computer how does it works? How can i accept connections accross internet?
    do you want the source code?
    Thanks and sorry for my English.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Alejandro, your first step is to connect your computer to the internet. You've probably already done this. If you can do this at the command line and see wikipedia's main page, then the first step is complete:
    Code:
    lynx http://www.wikipedia.org
    The next step, inside your program, is to translate the desired host name into an IP address. There are several ways to do this.
    1. The simplest way is to use gethostbyname().
    2. A way more likely to be thread safe (if you're using POSIX threads) is to use gethostbyname_r().
    3. A better way is to use getaddrinfo(). This way you'll be ready for IPV6, but the programming will be a little more complex.

    Once you have the IP address, you're good to go. Use it the same way you'd use the IP address of a local host.

    I highly recommend that you run (not walk) to your nearest bookseller and purchase the book UNIX Network Programming, volume 1, by W. Richard Stevens of happy memory, published by Addison Wesley. It contains much information that will save you time in the long run.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...