CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: C++ Sockets

  1. #1
    Join Date
    Nov 2008
    Posts
    2

    C++ Sockets

    Hi guys.
    I'm wondering how you can make multi-user sockets in C++? I use DevCPP, I know what it has stopped DEV though I still like to use it.

    In VisualBasic 6 You have "Indexs" is there a way you can do this so in C++, like in VB6 on Connection_Request you assign it a new index (Unload Socket(NewIndex), Then Load Socket(NewIndex)?).

    So, what shall I do? I don't want code::blocks please.

    Thanks guys.

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Smile Re: C++ Sockets

    I like very much Dev-cpp too. I still use it. I don't think it is really necessary to switch to code::blocks, because it is working with the same Mingw compiler.

    Sorry, I don't know LoadSocket.
    In C/C++, sockets can be used in many different ways (send or receive, UDP or TCP, retrieve data with recvfrom() or another function, etc.). You don't tell much about what you intend to do with sockets. Maybe a solution would be to have sockets on different ports, or to use threads, or to write data in a file and have access to that file from several applications, etc.

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: C++ Sockets

    What do you mena by a "multi-user socket"? Ordinarily, one socket will talk only to one other socket, not to multiple other sockets.

    If you want a program that will talk to multiple other parties, then the common approach is to create multiple sockets, each for talking with one other remote participant.

  4. #4
    Join Date
    Jul 2007
    Posts
    609

    Re: C++ Sockets

    This is where I learned most of what I know about socket programming:

    http://beej.us/guide/bgnet/

    I feel like a hypocrite as I can't stand when people just reply to a post with just a link, but that tutorial is very handy.

    A good idea is to make yourself a class so you can easily reuse it and not have to remember all the code behind it. You'll need a client class and a server class (and possibly other classes that work together depending how you do it).

    But to at least get your feet wet just play around with the code in that tutorial.
    http://www.uovalor.com :: Free UO Server

  5. #5
    Join Date
    Nov 2008
    Posts
    2

    Re: C++ Sockets

    Sorry for the slow reply,
    I'm trying to make a basic game server in C++, because I've made a game client in Flash/Actionscript.

    It needs to be able to talk to multiple sockets, any help?

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: C++ Sockets

    Quote Originally Posted by markh789 View Post
    Sorry for the slow reply,
    I'm trying to make a basic game server in C++, because I've made a game client in Flash/Actionscript.

    It needs to be able to talk to multiple sockets, any help?

    General Server configuration.

    1) A single socked is created to "Listen"
    2) When a Connection is Recieved, a NEW Socket is created which "Accepts" the connection. This socket will remain alive as long as THAT client is alive.
    3) The original socket goes back to listening.

    This means that if you have 1,234 clients playing your game, you have 1,235 sockets at that point in time.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: C++ Sockets

    Yes, but recognize that it is quite a challenge to build a server that can handle 1,234 client connections simultaneously.

    A few hundred is easy, but it quickly becomes difficult once you start thinking about 1,000 or more.

  8. #8
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: C++ Sockets

    Quote Originally Posted by MikeAThon View Post
    Yes, but recognize that it is quite a challenge to build a server that can handle 1,234 client connections simultaneously.

    A few hundred is easy, but it quickly becomes difficult once you start thinking about 1,000 or more.

    No argument with that..

    In reality large scale servers tend to adopt one of three approachs (in increaing order of complexity)

    1) Connectionless communication protocols
    2) Stateless short term connections
    3) Server Farms (large groups of computers to spread the load)

    I have done multiple commercial systems using all three approaches. The decision is not always simple, and the amount of information required to make the decision is much more than can resonably be covered in a forum environment.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured