473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Threads, C++ and the WinSock API

Hello. I am attempting to write a multiplayer game using C++ and the WinSock API. The game needs to be able to accept connections then read incoming requests, perform operations and write data back to the client. When the client does not respond for a certain amount of time or it wilfully disconnects, I need to be able to close the connection to the client.
Here is how I propose to handle this:
The server has a thread that waits for connections to be attempted; if the connection is successful, it puts the computer ID (or whatever) in an array. Then I have another thread that gets the port numbers and spawns a new thread for each of them (if there is not one already in existence). Each of the threads waits for commands and writes information back to the client. The thread that accepted connections and the thread that spawns new threads would have to be mutexable, correct?
I am not quite sure how to design this program, so any advice on the design would be helpful. My other problem (the reason that I posted this on the C++ forum XD) is this: I don't know how to properly create a thread or manipulate a thread at all. I have created threads briefly in Java, but from what I hear, C++ threads are quite different, correct?
Any suggestions, sample code, or links to a site with informaiton on the subject are appreciated :)

Thank you,
-wyrmmage
Oct 9 '06 #1
1 3062
Banfa
9,065 Expert Mod 8TB
Firstly a warning, do not unnecessarily create a lot of threads, you will just slow things down due to the amount of context switching taking place, do you really need a thread for every port opened? Remember if a single thread can not cope with talking through all those ports at the right speed then neither will multiple threads. Creating extra threads does give you any more processing power, this is limited by the CPU it just provides a way to easily manage things that are happening asynchronously (which I admit talking out of different ports would be).

Stricktly speaking C++ has no threads. However there are threads available in Windows. Unfortunately since I have never even waved a 10' pole at Java I have no idea what the differences might be because I do not know how Java threads work.

Look up CreateThread in you Windows documentation or AfxBeginThread or _beginthread.
Oct 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Niels Borg | last post by:
Hi, I'm writing app where I use WinSock, but I have experienced a problem. WinSock only sends the data after finishing the calling sub/function. Can I force WinSock immediately as I need to send...
3
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work...
1
by: Yu Chai | last post by:
Hi guys, I created a ASP page that 1. users can run when WinSock proxy are using (ie's one is unchecked) 2. users can't run when WinSock proxy are using (ie's one is checked) 3. users can't run...
1
by: christophe.anthon | last post by:
Hi, I have started with socket programmation and well no problem since now. But now i want to thread connections for the server and I got stuck in the topic of threads. Has someone here experience...
7
by: Nadav | last post by:
Hi I am writing some kind of a storage system that have to deal with large amounts of data passing over the net, Now, I Wonder... traditional programming would use win32 Winsock DLL as the means...
5
by: kc | last post by:
Hi Just upgrading a app from VB6 to VB.Net. All is going well apart from the Winsock control. The first thing we notice is that there does not appear to be a .Net version (please correct me if...
1
by: Nicolas Ghesquiere | last post by:
Hello I have a problem with my current program. The meaning of the program is to allow users to login to a server to allow them to access the internet. My program communicates with a MS isa...
6
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
3
AaronL
by: AaronL | last post by:
Hello, I am currently working on a project that has me in sort of a bind. What I want to do is retrieve web pages from the internet, and strip them down to just text. I'll get using Regular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.