I'm making asynchronous sockets in C++ right now, but I've stumbled upon an issue. I have a thread handling socket operations asynchronously, such as Connect and Send. However, if I let the thread handle asynchronous receiving too, the main program could continue running as expected, but nothing can be done with the socket until it's done receiving.
Should I make the thread receive when there's no operations in the queue and suspend and recreate it as soon as there's a new operation?
Overv, it sounds like the problem you're describing is that when you call a receive function when there's no actual input available on the socket, the thread blocks waiting for input, so it doesn't notice when there's data ready to be sent.
Operating systems typically provide a facility for multiplexing I/O to avoid unnecessary blocking. On a POSIX system (like Linux), [url=http://linux.die.net/man/2/select]select()[/url] and [url=http://linux.die.net/man/2/poll]poll()[/url] can be used for this purpose; in Windows, I think the analogous function is [url=http://msdn.microsoft.com/en-us/library/ms687025(VS.85).aspx]WaitForMultipleObjects()[/url].
You can use these functions to make your thread sleep until either input becomes available [i]or[/i] output is ready to send. When it wakes up it can check which it is and call either receive or send as appropriate, then go back to waiting. If you build your program's main loop around this, you may not even need a separate thread for the socket I/O.
The details of how to do this sort of thing are a bit involved, and depend on which OS you're using. It helps to use a library to abstract away the details -- since you're using C++, [url=http://think-async.com/]Asio[/url] would be a good candidate.
-snip-
problem solved
[QUOTE=Wyzard;22522067]-snip-[/QUOTE]
WinSock has select as well :)
So, i'm reading a text file line by line and i need to save everything before an whitespace in a string and the rest of the line in another string and do the same if there's an second whitespace, but i have no idea how to do it.
Using C#, btw.
You can use the [url=http://msdn.microsoft.com/en-us/library/b873y76a(v=VS.100).aspx]System.String.Split[/url] method for that.
[QUOTE=ZeekyHBomb;22560374]You can use the [URL="http://msdn.microsoft.com/en-us/library/b873y76a%28v=VS.100%29.aspx"]System.String.Split[/URL] method for that.[/QUOTE]
Thanks.
I made my first XNA game. How does one build the game into an .exe and make it playable for other peeps as well?
Split is the best option but what do you mean you have no idea how to do it?
You could go through the string and put every character in a buffer and when you reach the desired character push the buffer into an array and then set it to "". Repeat.
[QUOTE=Namelezz!;22563351]I made my first XNA game. How does one build the game into an .exe and make it playable for other peeps as well?[/QUOTE]
It should have been compiled into an executable already. If not that, what is the result of your compile?
Other people will probably only require Mono or .NET installed.
[QUOTE=ZeekyHBomb;22563463]It should have been compiled into an executable already. If not that, what is the result of your compile?
Other people will probably only require Mono or .NET installed.[/QUOTE]
Where is this .exe you speak of?
How shall I know D:
Depends on the IDE you've used, which I suspect you do since with a terminal you'd control the output path yourself.
Probably something among the lines of ProjectFolder/bin/Release. You should find that in the project settings somewhere as well.
Hey guys anybody got any good [B]3D[/B] tutorials for XNA? (Preferably not riemers)
[QUOTE=Darwin226;22578251][URL="http://creators.xna.com/en-US/education/gettingstarted/bg3d/chapter1"]http://creators.xna.com/en-US/education/gettingstarted/bg3d/chapter1[/URL][/QUOTE]
Thanks that's a good start but i need something that covers shaders and other advanced topics too.
You could probably find something that covers shaders specifically.
I guess
I have a little problem with XNA, it gives me a division by zero error and when I press a it decreases and when I press b it increases. Thats the opposite of what I was going for.
code :
[cpp]
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Released)
MathHelper.Clamp(numAttack += 1, 1, 10);
if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Released)
MathHelper.Clamp(numAttack -= 1, 1, 10);
shipX += GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X * shipSpeed;
shipY -= GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y * shipSpeed;
decorationRotation += 1;
deltaRotation = 360 / numAttack;
[/cpp]
line that gives the error : deltaRotation = 360 / numAttack;
You're using MathHelper.Clamp() to restrict the values of numAttack, but you're not doing anything with the return value.
Hence the division by zero - numAttack is obviously set to zero at some point
Is the initial value of numAttack > 0?
Ahh that explains it, how could I oversee that, and yes the initial value = 1
I am really having trouble with calculating vertex normals for lighting.
I have a heightmap and I managed to make it into a 3D terrain using DirectX, but now I can't figure out how to calculate the vertex normals to light it.
I really can't wrap my head around the math, and all the posts and snippets I saw about vertex normals only made me more confused, since some talk about weighting and averaging while others mention that their way is the fastest.
So if someone can explain how to calculate vertex normals or point me in the right direction I would be grateful!
I dunno how it's normally done, but you could get all triangles of which that vertex is a part of, calculate their normals and average them.
Let's name that vertex A and the others B and C.
You can calculate the triangle normal via the cross-product:
[code]triangleNormal = cross(B - A, C - A)[/code]
Do that for each triangle and finally average the result and then normalize the vector, so it's a proper normal.
Is there a website or something where i can search for libraries and their use, etc?
Something that's kinda the same to [url=http://luasearch.overvprojects.nl/]this[/url].
Libraries for C++
[url=http://www.cplusplus.com/reference/][u]This[/u][/url] website contains all of the standard libraries and lets you search them.
Thanks
There are over 9000 libraries for C++.
Normally I just use Google when I'm searching for a library for a certain task.
I'd snip that if I were you.:eng101:
[editline]06:47PM[/editline]
Oh yeah, quick C# question:
Let's say I have a string. ("Yes"). And I have a richTextBox. If I were to enter this string ("Yes") into the box, how could I have it automatically changed to another string ("No") and have it changed colors (To red/yellow/green/blue/indigo/violet).
Any ideas?
[QUOTE=Chad Mobile;22685583]I'd snip that if I were you.:eng101:[/QUOTE]
Why?
[QUOTE=Chad Mobile;22685583]Oh yeah, quick C# question:
Let's say I have a string. ("Yes"). And I have a richTextBox. If I were to enter this string ("Yes") into the box, how could I have it automatically changed to another string ("No") and have it changed colors (To red/yellow/green/blue/indigo/violet).
Any ideas?[/QUOTE]
TextChanged-Event and ForeColor-Property.
[cpp] private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.Text = richTextBox1.Text.Replace("If", "if");
}
[/cpp]
Doesn't work. :frown:
[editline]09:18PM[/editline]
For some reason it makes all the characters I enter backwards. If I type 'If' it types 'fI' like that annoying steam glitch.
Sorry, you need to Log In to post a reply to this thread.