Winsock Client + my game = problem

This is a discussion on Winsock Client + my game = problem within the C Programming forums, part of the General Programming Boards category; I made client using winsock (copy - paste it from MSDN), and also I made a server. I compiled Server ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    21

    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:

    Code:
    #include <allegro.h>
    #include <winalleg.h>
    #include <iostream>
    #include <fstream>
    #include <conio.h>
    #include <stdio.h>
    
    #ifndef _USE_OLD_OSTREAMS
    using namespace std;
    #endif
    
    #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:
    Code:
    #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..

    Thanks.
    Attached Files Attached Files

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    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
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    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, 04: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, 05: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21