Thread: How to use C to connect to a server

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Can you describe in a "bigger picture" what you want to do? There are probably several things that you could do, but it would help to understand more of what you are actually trying to do, so we can get the right solution.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #2
    Registered User
    Join Date
    Mar 2008
    Posts
    10
    Well the computer you're connecting to is going to have to be running a server of some sort. Also, your going to need the port that the server is listening on. I would read up on socket programming and that should get your going.


    -Dustin
    www.theCprogrammer.com

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    let me explain better...

    i have a c program and a configuration file with the server IP (and port if needed) and i need my program to connect to that computer, open and read a php file like:

    Code:
    <?
    $db_name = "xxxx";
    $db_ip = "xxx.xxx.x.xxx";
    $db_port = "xxxx";
    $db_user = "xxxx";
    $db_passwd = "xxxx";
    ?>
    and get the info inside it to use in the C program... in the example i need the xxxx part so if i can read the file i can get these...

    what i want to know is a way to connect to the server from the C program and go to file's path to read it... i suppose i can read the file with fopen / fread right?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    To read files from another machine, you need some sort of file transfer service on the remote machine.

    If you have free access to the server, then you should set up an SSH server, and use a SSH client (specifically "scp") on the local machine to copy the file across. Then it's a matter of reading/writing the file format. Which is

    If you haven't got free access to the server, you are either breaking the forum rules (cracking - not allowed to help you there), or you need to ask the owner of the server what services they supply when it comes to fetching/updating files, e.g. ftp or ssh for example.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    i have free access to the server... i must connect to this computer to read the info (usr, passwd, database etc) to use this info in my C program to connect to a mysql server automaticaly, but this info i need to read is in this specific computer and and i gota connect and read it automaticaly too...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to connect to a ftp server
    By Coding in forum Networking/Device Communication
    Replies: 6
    Last Post: 07-12-2010, 10:36 AM
  2. Can't get to connect clients to server
    By pyngz in forum C# Programming
    Replies: 2
    Last Post: 03-11-2009, 04:46 AM
  3. How to connect to an FTP server and download a file?
    By Comeback Kid in forum C Programming
    Replies: 1
    Last Post: 11-19-2005, 08:44 PM
  4. Client timed-out once on connect(), can never connect() again
    By registering in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-28-2003, 03:46 PM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM