Thread: Winsock Client + my game = problem

  1. #1
    Registered User
    Join Date
    Nov 2010

    Winsock Client + my game = problem

    I made client using winsock (copy - paste it from MSDN), and also I made a server.
    I compiled Server and Client, and they work fine, then i wanted to copy code of client into the code of my game. So when i start game it send message to the server, like client did that alone, without code of my game.

    And now there are a lot of errors and warnings (Errors:104, Warnings:24)

    In my game I use this libraries:

    #include <allegro.h>
    #include <winalleg.h>
    #include <iostream>
    #include <fstream>
    #include <conio.h>
    #include <stdio.h>
    #ifndef _USE_OLD_OSTREAMS
    using namespace std;
    #include "guicon.h"
    #include "grafika.h"
    #include <crtdbg.h>
    #define WINDOW_X 628
    #define WINDOW_Y 376 //511
    #define EXIT_X 200 //572
    #define EXIT_Y 200 // 486
    #define MAX_CHARACTERS 17
    #pragma comment(lib, "alleg.lib")
    and when i put into this:
    #define WIN32_LEAN_AND_MEAN
    #include <winsock2.h>
    #include <ws2tcpip.h>
    #include <stdlib.h>
    #include <stdio.h>
    // Need to link with Ws2_32.lib, Mswsock.lib, and Advapi32.lib
    #pragma comment (lib, "Ws2_32.lib")
    #pragma comment (lib, "Mswsock.lib")
    #pragma comment (lib, "AdvApi32.lib")
    #define DEFAULT_BUFLEN 512
    #define DEFAULT_PORT "27015"
    It says this: (Look the attachment file)

    What is a problem :/ it is says that ws2tcpip is problem, but this works if there is no code of my game.... It works fine then. When i merge this to codes, i get a lot of errors ://////// HELP please..


  2. #2
    Join Date
    Jul 2009
    No idea what's actually wrong, but try sorting your includes.
    (1) standard,
    (2) platform,
    (3) library.

    Furthermore, check the comments in your includes. It could be the case that one include depends on another, as is not uncommon.

  3. #3
    Join Date
    Aug 2010
    Ontario Canada
    1) There for you is an object lesson in why programmers invented the term "Script kiddies".... Copy and past code lumped together willy-nilly *almost never works*.

    2) You cannot use winsock without including windows... and yes the order does matter. Winsock2 first, then Windows, then ws2tcpip...

    3) Lose the "WIn32_LEAN_AND_MEAN" define because that offloads sub-headers that are needed to operate Winsock properly.

    4) Define a windows version, according to the winver header and be sure to load the appropriate version of Winsock, unless you want the thing working on some computers and not on others.

    My best advice to you --harsh though it may be-- is that you actually put in the time and learn Windows and Winsock programming and write your own code.
    Last edited by CommonTater; 11-10-2010 at 09:34 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  2. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  3. Winsock Webserver Problem
    By RunningBon in forum Networking/Device Communication
    Replies: 4
    Last Post: 06-08-2005, 04:05 PM
  4. Linking problem
    By Agent89 in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2005, 03:03 PM
  5. problem with my opegl game...
    By revelation437 in forum Game Programming
    Replies: 6
    Last Post: 11-25-2004, 11:32 AM