dude about sockets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Im starting working with sockets.

im making a server and a client (tipical starter) application.

About the BeginReceive Method, i dont understand why if i execute the line
one time, i only can send and receive a message, if i execute 10 times i can
send and receive 10... Do you know how BeginReceive method works?
 
Josema said:
Im starting working with sockets.

im making a server and a client (tipical starter) application.

About the BeginReceive Method, i dont understand why if i execute the line
one time, i only can send and receive a message, if i execute 10 times i can
send and receive 10... Do you know how BeginReceive method works?

It's not entirely clear what you mean. Could you give a concrete
example, preferrably with some code which shows the problem? See
http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
that.

Note that BeginRead gives you *asynchronous* IO - do you really need
that? You might want to try writing your code synchronously to start
with, then look at making it asynchronous.

Jon
 
Josema,

If you call the BeginReceive method, you are returned an implementation
of IAsyncResult, which represents that asynchronous call. The BeginSend
method will also allow you to pass a callback method which is executed when
the operation completes.

You should be able to do these as much as you want.
 
Just a guess here, but I'm thinking your problem has something to do
with always being able to read and write and not wanting to always call
BeginReceive. If you use your socket to obtain a NetworkStream, then
the NetworkStream object has some attributes that you can use to know
when to call BeginReceive. Some of these attributes are .DataAvailable,
..CanWrite, and .CanReceive. I hope these help and sorry if this isn't
what you meant.
 
Back
Top