473,651 Members | 2,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threads, C++ and the WinSock API

5 New Member
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 3076
Banfa
9,065 Recognized Expert Moderator Expert
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
3123
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 several packets but they have to be sent separate? Many thanks Niels Borg
3
694
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 around I can make on the C# side to hear the connect request? -Bill (don't reply by e-mail, the address is a fake) ______________________________ Steps to reproduce: Start the C# Listener
1
2533
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 when WinSock proxy are not using (ie's one is checked) 4. users can't run when WinSock proxy are not using (ie's one is unchecked) So, what is the difference between winsock proxy client and the proxy setting in browser (IE)?
1
2351
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 in how to use threads and how they work? Perhaps somebody can send me some code so that i will finally solve my problem. Thank you! Have a nice day, Christophe
7
2848
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 of data transportation... now, indigo is the new communication layer of the CLR, - Does indigo uses Winsock internally? - Is it possible to use indigo for such a task? - I assume using indigo has it's performance penalty ( doesn't it ? - Does...
5
6894
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 wrong). Also when we use the VB6 winsock control in a dotnet version we appear to lose the ability of creating an array on winsock's. for example we cannot assign as thus
1
5427
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 server to make a rule for that IP for the time-credits left for that user. My problem is that so far, the program can handle everything except more then one client, and i have done my best, but i can't find a decent solution
6
6443
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 fairly common idiom (at least in the Java/UNIX/Win32 worlds) where a socket connection is established and the program then utilises two threads: one dedicated to reading from the socket and the other one concurrently writing to the socket - both using...
3
7596
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 Expressions to strip out the HTML code itself, the problem is actually getting the web pages from the internet. I tried using the Microsoft Internet Transfer Control but my client was experiencing problems with some web pages not downloading, this...
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.