• Advertisement
Sign in to follow this  

multithreading mandatory?

This topic is 2155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm trying to make a simple little cmd tic tac toe with network support

im using sdl_net and tcp.

now i'm i've got the problem, that, when the server sends a message my client has to be ready to listen and send back .I think he problem is obviously : while my client is waiting for incomming data , the game is blocked.
Maybe i could solve it with multithreading, but i don't know if its the best solution. but if it is, i will accept it.
all i want to know is: shall i solve it with multithreading or is there a better way?

Share this post


Link to post
Share on other sites
Advertisement
Yes, but in my experience checksockets only works if somebodys looking for data. so if both are Checking sockets nobody's receiving and my Programm ends up in an endless loop. Or am i wrong?

Share this post


Link to post
Share on other sites

Yes, but in my experience checksockets only works if somebodys looking for data. so if both are Checking sockets nobody's receiving and my Programm ends up in an endless loop. Or am i wrong?

You are incorrect.

The underlying OS is still processing network events as usual while your program sits there waiting for socket activity. Once SDLNet_CheckSockets returns, it means that at least one socket in the set has received data while you were waiting.

Share this post


Link to post
Share on other sites
so what happends if client and server are both chekcing sockets at the same time?
And can i solve my problem without multitreading?

Share this post


Link to post
Share on other sites

so what happends if client and server are both chekcing sockets at the same time?

If neither of them sent anything first? They'll wait for ever. This is true whether or not you use multi-threading.

One of client/server has to send data in the first place, which the other will be waiting (in CheckSocket) to receive. Once it has sent data, the first can also go into CheckSocket, to wait for a response, and so on...

And can i solve my problem without multitreading?[/quote]
Yes.

Share this post


Link to post
Share on other sites
yes it works but something strange happens:
on the serverside the server can make about 30 SDLNet_CheckSockets(set,0) loops without getting or sending a message from the client.
the output looks like this(each "-" means an empty loop):
------------------------------
pong 0
----------------
pong 1
------------------------------------------------------
pong 2
...
but on the client side it looks like this,unless i stopp the server by holding the scrollbar in the console :
-
pong 0
-
pong 1
-
pong 2
...

is that normal?

btw when i holding the scrollbar on one side it looks like this on the other side (until i release it) it looks like this. So this check sockets stuff works great
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
im so sorry...
i used system("color 5a");
on the client to distinguish between client and server.
this has greatly slowed down my programm.
so my Problem is solved till now.
Nice Weekend.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement