Thread: newbie question

  1. #1
    Registered User invisibleghost's Avatar
    Join Date
    Jun 2004
    Posts
    28

    newbie question

    Here my prob i try to start my code but i not sure it well connect.here it is.


    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <stdio.h>

    int connect(int sockfd, const struct sockaddr serv addr, socklen_t addrlen);



    That how i start it so far.did i make any mistakes?

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Depends on whether you're using Windows or Unix. If Windows you'll need to use winsock. For Unix, you're looking good so far here is some more info.

  3. #3
    Registered User invisibleghost's Avatar
    Join Date
    Jun 2004
    Posts
    28
    yes i useing linux but i am takeing alot of notes when i doing this

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Before you connect(), you must create the socket(), and fill out the sockaddr_in struct. I suggest checking out Beej's Network Programming Tutorial, read it carefully and run the example code, and then check out and search the Networking/Device Communication section of the boards for relevent threads, search the internet, whatever.

    Also, just:

    Code:
    int connect(int sockfd, const struct sockaddr serv addr, socklen_t addrlen);
    Won't do anything by itself. It is a function prototype specifying the parameters it takes. A call to the connect function in your code might look like: connect(Socket, (struct sockaddr*)&hostAddr, sizeof(struct sockaddr)), where Socket is the int returned from the socket() function, and hostAddr is the filled out sockaddr_in struct.

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by invisibleghost
    yes i useing linux but i am takeing alot of notes when i doing this
    you speel reel good

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM