Thread: Why might I be getting these errors? (WinSock2)

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    69

    Exclamation Why might I be getting these errors? (WinSock2)

    I'm getting the following errors:


    Quote Originally Posted by Microsoft Visual C++ Express
    1>------ Build started: Project: HTTP BOT, Configuration: Debug Win32 ------
    1> httpBotBase.c
    1>c:\users\stdioDOTh\desktop\http bot\http bot\bot.h(21): error C2061: syntax error : identifier 'wsaData'
    1>c:\users\stdioDOTh\desktop\http bot\http bot\bot.h(21): error C2059: syntax error : ';'
    1>c:\users\stdioDOTh\desktop\http bot\http bot\httpbotbase.c(13): error C2065: 'wsaData' : undeclared identifier
    1>c:\users\stdioDOTh\desktop\http bot\http bot\httpbotbase.c(13): warning C4133: 'function' : incompatible types - from 'int *' to 'LPWSADATA'
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Files:


    bot.h
    Code:
    
    #define WIN32_LEAN_AND_MEAN
    
    
    #include <Windows.h>
    #include <WinSock2.h>
    #include <ws2tcpip.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    
    #pragma comment(lib, "ws2_32.lib")
    
    
    //Prototypes
    void exitProcess(void);
    int botConnect(void);
    
    
    //Configuration these aren't used yet
    #define PORT		"80"
    #define SERVERIP	"127.0.0.1"
    
    
    //
    WSAData wsaData;
    SOCKET Socket;
    SOCKADDR_IN service;
    LPHOSTENT host;

    httpBotBase.c
    Code:
    
    #include "Bot.h"
    
    
    int main(int argc, char *argv[])
    {
    	atexit(exitProcess);
    	botConnect();
    	return 0;
    }
    
    
    int botConnect()
    {
    
    
    	if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
    		return 1;
    
    
    	Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    
    
    	if (Socket < 0)
    		return 1;
    
    
    	service.sin_family = AF_INET;
    	service.sin_port = htons(80); //Change this to PORT
    
    
    	host = gethostbyname("127.0.0.1");
    	if (!host) //Change this to SERVERIP
    		return 1;
    
    
    	printf("Successfully reached this point!");
    
    
    }
    
    
    
    
    void exitProcess()
    {
    	puts("Program is now exiting.");
    	Sleep(2000);
    	getchar();
    }

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Shouldn't WSAData be WSADATA (all caps) ?

    And you're not using the header file properly. It's not supposed to contain everything its associated code file needs; it's supposed to contain everything that ANOTHER code file needs to use the associated code file. You don't really need one for the code you've posted, so I suggest you move the contents of bot.h into httpBotBase.c.

    And the variables shouldn't be global if they don't have to be.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Thank you, I can't believe I was so stupid to miss that. Yeah, how I set out the header file isn't how it's 'supposed to be', but I did it for simplicity. I was going to move all unneeded code back once it was working correctly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with winsock2
    By Hermitsky in forum Networking/Device Communication
    Replies: 4
    Last Post: 10-16-2005, 04:48 PM
  2. Linker errors on Winsock2 functions
    By ShadowMetis in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2004, 11:19 PM
  3. cant use winsock2 in dev-c++
    By datainjector in forum Tech Board
    Replies: 2
    Last Post: 08-30-2003, 03:55 PM
  4. Errors when including winsock2.h
    By skiingwiz in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2002, 07:32 PM
  5. Winsock2.h
    By Engineer in forum Windows Programming
    Replies: 4
    Last Post: 10-12-2001, 06:48 PM