المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : c# sockets [modified]



C# Programming
01-03-2010, 04:40 PM
i need some guidance regarding c# winsock programming, im a beginner in programming and network applications. i understand the client/server idea.

server -> socket() bind() listen() accept() {send() recv()} close()

client -> socket() connect() {send() recv()} close()

--

i also know Socket.Connected Property to test if connected.

--

where i am having difficulty is in both server and client how to implement send() and recv() [events]. i know how to send and receive but to do it while keeping the connection seems to very vague in google links.

most examples on google just creat the connection and may send some data or receive some data and the connection is closed.

the while(true) on server runs in a loop and accepts new connections.

i need to know how to implement send and recv (events) so the connected clients and server can keep on exchanging data using the same connection.

lots of the web examples have the server running in a loop and the client makes a new connection whenever data needs to be sent, it doesn't seem efficient to me.

i have also seen server loop running on its own thread to avoid gui lockups but there also the actual communication seems vague.

so. i would like info on how to handle send and recv in a structured manner.

thanks for reading and a very happy new year to you.

---------------------

my current approach is wrong, it concerns blocking.. i should be using .NET asynchronous socket programming.

thanks.

modified on Saturday, January 2, 2010 1:36 PM