Thread: Where to get this socket.h?

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    195

    Where to get this socket.h?

    i downloaded a small program that shows the basics of this socket thing but it says that i cant find socket.h? Help pls thanks

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    most likely you want to use
    #include <winsock2.h> instead?

    I'm not sure exactly what you're trying to use this program for, but I know that when I use winsock, I use the winsock2.h header, but it seems like you're looking for a different file...?

    try a google search if winsock isn't what you're looking for

  3. #3
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    I socket.h soupoused to come with the porgram (something like a wrapper for sockets)? I don't remember it being any of the headers in *nix.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  4. #4
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    actually, socket.h is part of the *nix GCC system includes. it is under the directory sys in /usr/include .

    although how they are calling it just "socket.h" makes me wonder as you usually have to include it with "sys/socket.h"

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    195
    Well here is the program i dunno how to execute/compile it

    Code:
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <unistd.h>
    
    #include <iostream>
    #include <string>
    
    int main(int argc,char* argv[])
    {
    
       if (argc < 2)
       {
           std::cout << "Please specify a stock symbol\n";
           exit(1);
       }
    
       struct sockaddr_in    address;
       address.sin_family    = AF_INET;
       address.sin_port      = htons(80);
       inet_aton("66.94.228.229",&address.sin_addr);
    
       int sockNo    = socket(PF_INET,SOCK_STREAM,0);
       int result    = connect(sockNo,(sockaddr*)&address,sizeof(struct sockaddr_in));
    
       if (result == 0)
       {
           /* We have a connection */
           std::string    getRequest("GET /d/quotes.csv?f=l1&s=");
    
           getRequest    += argv[1];
           getRequest    += "\r\n";
           write(sockNo,getRequest.c_str(),getRequest.length());
    
           char    buffer[2000];
           read(sockNo,buffer,2000);
    
           std::cout << "Stock Price of " << argv[1] << " is " << buffer;
       }
       else
       {
           std::cout << "Failed to Connect\n";
       }
       return(0);
    }

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i dunno how to execute/compile it
    There should be a button on your compiler called "Run". Press that.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Ohh, lets play a game of "guess the compiler and OS"
    On second thoughts, lets just wait for the OP
    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. Socket programming in C with socket.h
    By funzy in forum Networking/Device Communication
    Replies: 13
    Last Post: 08-29-2008, 04:12 AM
  2. Problem with Socket.h in C
    By Yuushi in forum Networking/Device Communication
    Replies: 6
    Last Post: 10-10-2007, 05:33 AM
  3. Does anyone have 'socket.h'?
    By bigredgiant1 in forum C Programming
    Replies: 2
    Last Post: 12-24-2001, 11:55 AM