c# sockets

help with send recv

Page 1 of 1

5 Replies - 4232 Views - Last Post: 04 January 2010 - 06:41 AM Rate Topic: -----

#1 ikurtz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 09-December 09

c# sockets

Posted 02 January 2010 - 09:29 AM

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.

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

i think the knowledge i have at the moment is wrong. i am taking a blocking approach where i should be implementing asynchronous sockets ( asynchronous) IO.

------

This post has been edited by ikurtz: 02 January 2010 - 11:27 AM


Is This A Good Question/Topic? 0
  • +

Replies To: c# sockets

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: c# sockets

Posted 02 January 2010 - 09:38 AM

Client:
create socket
connect to server 
-->send data
-->recv response - if 0 bytes received, server closed connection
-->repeat until done
close socket


Server:
create socket
bind to socket
accept connection
-->recv data --> if 0 bytes received on initial call, client disconnected gracefully; else wait for timeout
	 --> continue until either 0 bytes received or timeout
	 -->send response
-->repeat previous
close socket

Was This Post Helpful? 0
  • +
  • -

#3 QuackWare   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 02-January 10

Re: c# sockets

Posted 02 January 2010 - 12:08 PM

These {LINK REMOVED} should help you out.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: c# sockets

Posted 03 January 2010 - 12:04 AM

@QuackWare: Please stop from trying to lead the members of Dream.In.Code to some code site you obviously support and want to advertise. Now dont get me wrong, feel free to help them here in this community, just do it in a way where you're not leading them to one of your sites please.

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#5 batesy3k   User is offline

  • D.I.C Regular

Reputation: 41
  • View blog
  • Posts: 299
  • Joined: 10-September 09

Re: c# sockets

Posted 04 January 2010 - 03:35 AM

has anyone got a nice tutorial on this as all the examples I have seen have been very vague also, no "real" tutorials on simple sending and recieving data between client and server and how to handle multiple connections to the server...
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: c# sockets

Posted 04 January 2010 - 06:41 AM

Google C# socket server tutorial and click the 3rd link.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1