How to use threads in socket programming?  
Author Message
yabansu





PostPosted: .NET Framework Networking and Communication, How to use threads in socket programming? Top

Hi all,

I implemented a simple server(with C#) and a simple client(with C++) application. They are communicating very well. I want to use threads for enhancing the communication since there will be more than one client application which sends various messages to the server and server will have to handle them by sending the clients acknowledments.

I need some examples in which thread/socket programming is used. Is there anyone to help me

Thanks...



.NET Development22  
 
 
Sean Hederman





PostPosted: .NET Framework Networking and Communication, How to use threads in socket programming? Top

Have a look at: http://msdn2.microsoft.com/en-us/library/fx6588te.aspx and http://www.codeproject.com/cs/internet/AsyncSocketServerandClien.asp for some ideas.

 
 
Indian Ocean





PostPosted: .NET Framework Networking and Communication, How to use threads in socket programming? Top

Hi,

You can use asynchronous Socket APIs for multithreaded socket application:

For Asynchronous Server example:
http://msdn2.microsoft.com/en-us/library/fx6588te.aspx
http://msdn2.microsoft.com/en-us/library/5w7b7x5f.aspx

For Asynchronous Client example:
http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx
http://msdn2.microsoft.com/en-us/library/bew39x2a.aspx

HTH,



 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, How to use threads in socket programming? Top

Threads are not a good choice to implement a multi client server and your application may consume more CPU time by using them if you have many clients and may even crash when this overhead increases. So in simple no body recomends to create thread on per request basis.

The best Solution to implement such application is to use Asynchronous Sockets, which will ensure your application is consuming no more CPU than it requires and behave well and also lets behave other application run good.

Some Basic Information:

http://www.codeproject.com/cs/internet/asyncsockets2.asp

Something to really Study keenly:

http://www.developerfusion.co.uk/show/3997/3/

Get Started for some Real Application:

http://www.codeproject.com/cs/internet/socketsincs.asp

Some Others:

http://www.codeproject.com/cs/internet/AsyncSocketServerandClien.asp

And sure don't forget to consult MSDN before you start reading these articles because MSDN provides very detailed information about each method.

I hope this will help.

Best Regards,

RIzwan aka RizwanSharp



 
 
yabansu





PostPosted: .NET Framework Networking and Communication, How to use threads in socket programming? Top

Hello friends,

I have read the articles you referred and got the simple idea... Asynchronous Sockets are actually what I need!

But I have also a big problem:
It is not difficult to implement the asynchronous sockets using .Net library in the server side(written in C#), but how can I do it in the client side(written in pure C++) too

Thank you very much!


 
 
Indian Ocean





PostPosted: .NET Framework Networking and Communication, How to use threads in socket programming? Top

Hi,

Please refer the following links for samples of Socket client in C++:

All type of Socket related C++ link in the post at http://www.codeguru.com/forum/showthread.php t=326666
Client: http://www.codersource.net/win32_socket_client.html
C++, Java Socket server/client: http://sage.mc.yu.edu/kbeen/teaching/networking/resources/sockets.html

I think, first link is good enough for your requirement,

HTH,