MYE
MYE

Reputation: 1003

Asynchronous / Synchronous and TCP or UDP

I very confuse about Synchronous and Asynchronous Socket in C#, i want develop a game play on LAN network, but i confuse which one is better for my application Hangman game.

This game can play with 1player mode or 2 players mode.

In 1 player mode just a player interact with serer

But 2 players mode 2 players interact with server by turn base. It mean if player A guess wrong word, he lose his turn and player B take this turn.

Can you give me suggest about Synchornous and Asynchronous.

Beside that how can client can find server if client dont need enter server ip? it mean what should i choose between TCP and UDP

and last question is can i create a server is asynchronous but clients are synchronous, is it ok?

Thank You Very much

Upvotes: 2

Views: 12083

Answers (2)

Lucian Enache
Lucian Enache

Reputation: 2530

so regarding your questions :

Can you give me suggest about Synchornous and Asynchronous: In your case given the complexity of the application you can use either sync or async sockets, as twilson stated the sync sockets blocks your main thread while the async ones don't so if you have performance issues go for the asynchronous sockets

Beside that how can client can find server if client dont need enter server ip? it mean what should i choose between TCP and UDP: well there's a fair difference between TCP and UDP connections, you usually use UDP (connectionless) when you have peformance issues like Voip apps, real time games,video chat and so on, while in onther cases you use TCP, so in your case TCP should suit you good.

and last question is can i create a server is asynchronous but clients are synchronous, is it ok? Yes you could use this kind of implementantion even if it.s a good practice to have the same type of socket on both clients and server.

Upvotes: 1

Mark Smith
Mark Smith

Reputation: 1115

The important part of about choosing Asynchronous vs Synchronous is how you make the communications interact with your GUI thread. Don't let a synchronous socket block your UI. I see the article here gives an idea what to expect and gives some guidance about using Asynchronous with Windows programming. Winsock tips

Your second question about TCP/UDP there are a lot of difference between the two you should be aware of. First and foremost, TCP is going to guaranteed packet delivery while the connection is valid. Given your situation and the simple requirements and lack of performance needs. TCP is probably your best choice. If you are designing a high performance game where you have to allow for dropped packets and handle latency better, UDP becomes a better option but then you have to take into consideration what happens when you drop packets and have things like Out of Order packets. TCP hides all of that complexity from you and will make working with it simpler.

Mixing synchronous and Asynchronous client/server should cause not problems. They only know about the communication link itself (TCP/UDP).

Upvotes: 1

Related Questions