socket.Send and socket.Receive at the same time 
Author Message
 socket.Send and socket.Receive at the same time

Hello!

May socket.Send and socket.Receive for the same socket object be invoked at
the same time by two different threads?

Best regards,

Henrik Dahl



Sun, 09 Jan 2005 03:12:45 GMT  
 socket.Send and socket.Receive at the same time
Henrik, no, you can't send and receive from one socket at the same time.
You'll have to use a different port/socket if you need to go at the same
time or use thread synchronization (check out Monitor, Lock, Mutex) to make
sure one or the other is happening but not both.

--
Greg
http://www.claritycon.com/


Quote:
> Hello!

> May socket.Send and socket.Receive for the same socket object be invoked
at
> the same time by two different threads?

> Best regards,

> Henrik Dahl



Sun, 09 Jan 2005 03:17:52 GMT  
 socket.Send and socket.Receive at the same time
Henrik,

    I don't think you can.  As far as I know, making calls on a socket that
is created on another thread gives unpredictable results.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hello!

> May socket.Send and socket.Receive for the same socket object be invoked
at
> the same time by two different threads?

> Best regards,

> Henrik Dahl



Sun, 09 Jan 2005 03:20:26 GMT  
 socket.Send and socket.Receive at the same time
Greg,

OK, but how do I then program that I may basically always receive something
from the server and also be able to send something to it from time to time?

Henrik


Quote:
> Henrik, no, you can't send and receive from one socket at the same time.
> You'll have to use a different port/socket if you need to go at the same
> time or use thread synchronization (check out Monitor, Lock, Mutex) to
make
> sure one or the other is happening but not both.

> --
> Greg
> http://www.claritycon.com/



> > Hello!

> > May socket.Send and socket.Receive for the same socket object be invoked
> at
> > the same time by two different threads?

> > Best regards,

> > Henrik Dahl



Sun, 09 Jan 2005 04:02:48 GMT  
 socket.Send and socket.Receive at the same time
Nicholas,

OK, but how do I then program that I may basically always receive something
from the server and also be able to send something to it from time to time?

Henrik



Quote:
> Henrik,

>     I don't think you can.  As far as I know, making calls on a socket
that
> is created on another thread gives unpredictable results.

>     Hope this helps.

> --
>                - Nicholas Paldino [.NET MVP]



> > Hello!

> > May socket.Send and socket.Receive for the same socket object be invoked
> at
> > the same time by two different threads?

> > Best regards,

> > Henrik Dahl



Sun, 09 Jan 2005 04:03:04 GMT  
 socket.Send and socket.Receive at the same time
Well, you can't send and receive at the EXACT SAME time, but you
can send and receive.

So what you need to do in your threads is, when you're about to
read or write, lock on an object (mutex, etc) read or write, then
release the lock.

If another thread tries to read/write, it will block on the lock
call until the other thread is done and then perform its operation.

-c


Quote:
> Nicholas,

> OK, but how do I then program that I may basically always receive
something
> from the server and also be able to send something to it from time to
time?

> Henrik


wrote

> > Henrik,

> >     I don't think you can.  As far as I know, making calls on a socket
> that
> > is created on another thread gives unpredictable results.

> >     Hope this helps.

> > --
> >                - Nicholas Paldino [.NET MVP]



> > > Hello!

> > > May socket.Send and socket.Receive for the same socket object be
invoked
> > at
> > > the same time by two different threads?

> > > Best regards,

> > > Henrik Dahl



Sun, 09 Jan 2005 04:15:18 GMT  
 socket.Send and socket.Receive at the same time

Quote:

>May socket.Send and socket.Receive for the same socket object be invoked at
>the same time by two different threads?

I hope so, I've done it several times!  I'm not sure why the others in this
thread think it should be a problem since it is fairly common in blocking
scenarios for one thread to be a reader while another is a writer.

--

*--------={ Fine Art for .NET }=--------*

*---------------------------------------*

       Turn on, tune in, download.



Sun, 09 Jan 2005 04:19:35 GMT  
 socket.Send and socket.Receive at the same time

Quote:

>So what you need to do in your threads is, when you're about to
>read or write, lock on an object (mutex, etc) read or write, then
>release the lock.

I'm not clear on why everyone thinks there's an issue with threading and
sockets. Do you have specific information indicating there's some problem in the
BCL with simultaneously executing blocking reads and writes on a single socket
or are you speaking from general principles?  A socket is not a file. :-)

--

*--------={ Fine Art for .NET }=--------*

*---------------------------------------*

       Turn on, tune in, download.



Sun, 09 Jan 2005 04:22:20 GMT  
 socket.Send and socket.Receive at the same time
Yes, but as the server takes the initiative to send something to the client,
I suppose that the client should basically receive in order to have the
server to succeed, and as the client would like to send the client should be
able to do that. How do I make the client in such a way, that the server may
succeed in sending to the client when it wants and the client may succeed in
sending to the server when it wants?


Quote:
> Well, you can't send and receive at the EXACT SAME time, but you
> can send and receive.

> So what you need to do in your threads is, when you're about to
> read or write, lock on an object (mutex, etc) read or write, then
> release the lock.

> If another thread tries to read/write, it will block on the lock
> call until the other thread is done and then perform its operation.

> -c



> > Nicholas,

> > OK, but how do I then program that I may basically always receive
> something
> > from the server and also be able to send something to it from time to
> time?

> > Henrik


> wrote

> > > Henrik,

> > >     I don't think you can.  As far as I know, making calls on a socket
> > that
> > > is created on another thread gives unpredictable results.

> > >     Hope this helps.

> > > --
> > >                - Nicholas Paldino [.NET MVP]



> > > > Hello!

> > > > May socket.Send and socket.Receive for the same socket object be
> invoked
> > > at
> > > > the same time by two different threads?

> > > > Best regards,

> > > > Henrik Dahl



Sun, 09 Jan 2005 04:22:22 GMT  
 socket.Send and socket.Receive at the same time
Thanks, that's my point of course.



Quote:

> >May socket.Send and socket.Receive for the same socket object be invoked
at
> >the same time by two different threads?

> I hope so, I've done it several times!  I'm not sure why the others in
this
> thread think it should be a problem since it is fairly common in blocking
> scenarios for one thread to be a reader while another is a writer.

> --

> *--------={ Fine Art for .NET }=--------*

> *---------------------------------------*

>        Turn on, tune in, download.




Sun, 09 Jan 2005 04:25:51 GMT  
 socket.Send and socket.Receive at the same time

Quote:

>How do I make the client in such a way, that the server may
>succeed in sending to the client when it wants and the client may succeed in
>sending to the server when it wants?

I think the other people here are wrong.  I seem to recall having done blocking
reads and writes on a single socket more than once in the past,  although I
usually prefer to use asynchronous methods.  I have some sample projects and
powerpoint slides at www.abderaware.com - look in the Free Stuff folder.  You
can probably adapt code from one or more of the sample projects for whatever it
is you're trying to do.

--

*--------={ Fine Art for .NET }=--------*

*---------------------------------------*

       Turn on, tune in, download.



Sun, 09 Jan 2005 04:35:56 GMT  
 socket.Send and socket.Receive at the same time



Quote:

> >So what you need to do in your threads is, when you're about to
> >read or write, lock on an object (mutex, etc) read or write, then
> >release the lock.

> I'm not clear on why everyone thinks there's an issue with threading and
> sockets. Do you have specific information indicating there's some problem
in the
> BCL with simultaneously executing blocking reads and writes on a single
socket
> or are you speaking from general principles?  A socket is not a file. :-)

I was goind to say that I though socket supported simultaneous reads
and writes, but everyone seemed to agree that it didn't, so I figured
I must've been wrong and that I got lucky my program didn't crash =)

-c



Sun, 09 Jan 2005 04:36:39 GMT  
 socket.Send and socket.Receive at the same time
Zane,

Thank you very much!

Henrik



Quote:

> >How do I make the client in such a way, that the server may
> >succeed in sending to the client when it wants and the client may succeed
in
> >sending to the server when it wants?

> I think the other people here are wrong.  I seem to recall having done
blocking
> reads and writes on a single socket more than once in the past,  although
I
> usually prefer to use asynchronous methods.  I have some sample projects
and
> powerpoint slides at www.abderaware.com - look in the Free Stuff folder.
You
> can probably adapt code from one or more of the sample projects for
whatever it
> is you're trying to do.

> --

> *--------={ Fine Art for .NET }=--------*

> *---------------------------------------*

>        Turn on, tune in, download.




Sun, 09 Jan 2005 04:38:56 GMT  
 socket.Send and socket.Receive at the same time
On Tue, 23 Jul 2002 15:36:39 -0500, "Chad Myers"

Quote:

>everyone seemed to agree

Sometimes it's better to be a rebel. ;-)

--

*--------={ Fine Art for .NET }=--------*

*---------------------------------------*

       Turn on, tune in, download.



Sun, 09 Jan 2005 04:41:38 GMT  
 socket.Send and socket.Receive at the same time
Zane,

One more question. Let's assume I do it asynchronously using
socket.BeginSend. Do you know, it I can invoke a number of socket.BeginSend
invokations after each other without waiting for the previous one to finish
or does it mix up the sequence of bytes actually sent.

Best regards,

Henrik



Quote:

> >How do I make the client in such a way, that the server may
> >succeed in sending to the client when it wants and the client may succeed
in
> >sending to the server when it wants?

> I think the other people here are wrong.  I seem to recall having done
blocking
> reads and writes on a single socket more than once in the past,  although
I
> usually prefer to use asynchronous methods.  I have some sample projects
and
> powerpoint slides at www.abderaware.com - look in the Free Stuff folder.
You
> can probably adapt code from one or more of the sample projects for
whatever it
> is you're trying to do.

> --

> *--------={ Fine Art for .NET }=--------*

> *---------------------------------------*

>        Turn on, tune in, download.




Sun, 09 Jan 2005 04:45:42 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Socket.Send Socket.Receive

2. Sending/Receiving a Structure via Sockets

3. Help, looking for: asynchronously send/receive example with a tcp sockets

4. send socket from socket

5. Socket.Receive problems

6. Byte [] pointer arithmetic for socket receive

7. Asynchronous socket & recursive receiving

8. Closing socket when using Async Receive methods

9. Halt At Socket.Receive() Statement

10. Asynchronous Socket Data Receiving Problem

11. Receiving huge data with DataStream Sockets

12. How to receive jpg files on a socket

 

 
Powered by phpBB® Forum Software