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
Printable View
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
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
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.
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"
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);
}
There should be a button on your compiler called "Run". Press that.Quote:
i dunno how to execute/compile it
Ohh, lets play a game of "guess the compiler and OS"
On second thoughts, lets just wait for the OP