C++ Networked BlackJack Card Game

Posted on 2011-04-28
Last Modified: 2012-06-21
Dear Experts,

I have been developing a C++ game over the last few days with your assistance.

I need your help in one final little instance, I am attempting to get the game to connect to another client as a server, but it fails to connect - very strange. I have been racking my brains over this all last night, and cannot find the answer.

I have included a Mediafire locker, with the p-a-ssw-o-rd protected content as this is proprietary code.

Please note these are RAR files, and the p-assw-ord is shown within the image attached. If you could please take a look at my application, and see if there is anything wrong with it, I would be extremely grateful.

If you can see any other errors, please discuss them - but please be careful about discussing individual code.

Code Share Folder:

Kind Regards,

As described
Question by:SME_Paddington
    LVL 32

    Accepted Solution

    can you tell what errors you get when connecting to another client?

    what is the value you get when calling WSAGetLastError() ?

    did you get the output "Exiting because Connect failed" from CSimpleClient_TCP::Connect ?

    did you ever achieved to connect to an other client/server?


    Author Comment

    Hi Sara,

    I have not checked yet WSAGetLastError().

    Yes, from CSimpleClient_TCP:Connect... I received that exact error.

     I am able to have a client connect to the server console, but I am not able to initiate a remote connection to the other server.


     Client -> Server    = Working Perfectly
     Server <- Client    = Attempting to connect failed. I normally receive the error: Bind() failed.

    After having edited the code, it now times out. I appreciate you taking time to look at my code.

    There is also one last file for the CSimpleClient_TCP which I was not able to initialise (that is included in the original built file). I will upload that to the media share, same p4ss-w0rd as before. It could be the source of the problem.

    Kind Regards
    LVL 32

    Expert Comment

    for remote connection you need your firewall to allow that. did you use windows firewall or firewall from antivirus (or both???)  ?

    the settings of your firewall should allow you to open output connections for some ports.

    how do you address the remote server? by name or by ip? if ip address, is it ip4 or ip6?

    if by name, are you able to ping at the commandline using that name? if not you should either add the name - ip relation to hosts file (on xp it is at system32\drivers\etc) or change the server name to ip address in your client.

    unfortunately there are many reasons why a socket connection to a remote server could fail. can you call the WSAGetLastError() and check in winerror.h what the return value means?


    Author Comment

    I have been using port: 8015, and essentially this is not blocked by either firewall. (I have not tried turning off the firewall yet).

    I was connecting to a remote computer on my network, which is connected locally via the use of Wireless. When not connected via via wireless it would not allow the connection, as it was blocked by 2 routers that exist on the network in between the 2 nodes.

    Situation 1 (Wired Cable) :
    MyComp ==> Router 1 ( Access) ==> Router 2 ==> Remote PC

    RemotePC fails to connect to MyComp.

    Situation 2 (Wireless):
    MyComp ==> Router 1 ( Access) ~~~~> RemotePC

    MyComp fails to connect to RemotePC

    Remote Connection performed by IP. IPV4.

    Okay Sara, will do as soon as I have written up the report for this coding I will check out the WSAGetLastError() message. Please bear with me, as I am submitting this tonight. As soon as the report is done, I will update you on the status of the errors.

    Author Comment

    You may be right, looking at it now, if remote connections to the local IP are blocked, then it could essentially stop communication from occurring whereas remote connections from the local IP are not blocked...

    Situation 1 and Situation 2 have not been fully tested with all states please note.
    LVL 32

    Assisted Solution

    by the way, you wouldn't bind a socket at the client side when connecting to a server. the bind was made by the server only. so you shouldn't get a bind error beside you would use the same port (number) for receive (where your clients listens for other clients to connect) socket  and send socket (the one which fails).


    Author Closing Comment

    Debugging with this function found the error.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now