arent u using BeginConnect,BeginReceive,BeginSend etc ....... I guess these
are executed on thread pool
I'm using BeginReceive and I thought about using BeginConnect, but what
do I need to do tell that I'm waiting for async callback. The process
is that I connect to the machine, then send a command. So I need to be
able to wait for the connect before I send my data. Thought about
using socket.Connect() but that will block all thread right?
> arent u using BeginConnect,BeginReceive,BeginSend etc ....... I guess these
>
[quoted text clipped - 15 lines]
> > able to keep trying to re-connect to the machine. But I don't want the
> > "re-connect" to block communication with the other machines. Any ideas?- Hide quoted text -- Show quoted text -
Henning Krause [MVP - Exchange] - 24 Jan 2007 15:21 GMT
Hello,
when you use BeginConnect, you can pass along a callback delegate, which
will be called, once the connection has been established or when the
connection failed. In this callback, you call EndConnect. After that, you
can send data using the Send method.
This way, you won't block the base thread.
Best regards,
Henning Krause
> I'm using BeginReceive and I thought about using BeginConnect, but what
> do I need to do tell that I'm waiting for async callback. The process
[quoted text clipped - 23 lines]
>> > "re-connect" to block communication with the other machines. Any
>> > ideas?- Hide quoted text -- Show quoted text -
Ryan - 24 Jan 2007 16:29 GMT
Thanks for the help thus far.
BeginConnect is halting the main thread. Let me clarify some things.
Since I have to manually handshake with the device, I wrote a
controller class to handle communication for each machine. In my
service app, I have a collection of "controller" objects to connect to
each machine. When it starts, I iterate through each object to
connect, then send data to start the data retrieval from the machine.
I'm using a network stream to handle the data, but its being called
before the async call back. I tried a ManualResetEvent object but that
didn't work. But my issue still is how can say (for each controller
object) connect to your machine and send the data but only if the
connection has been made. If I can get that working, then I should be
able to figure out how to reconnect to the machine if its turned off
without affecting the "controller" objects
On Jan 24, 10:21 am, "Henning Krause [MVP - Exchange]"
<newsgroups_rem...@this.infinitec.de> wrote:
> Hello,
>
[quoted text clipped - 35 lines]
> >> > "re-connect" to block communication with the other machines. Any
> >> > ideas?- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Ryan - 24 Jan 2007 16:30 GMT
Sorry, meant to say BeginConnect is NOT halting my main thread in my
service app.
> Thanks for the help thus far.
>
[quoted text clipped - 54 lines]
> > >> > "re-connect" to block communication with the other machines. Any
> > >> > ideas?- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Henning Krause [MVP - Exchange] - 24 Jan 2007 16:47 GMT
Of course it's not blocking your thread - that's what it's for.
As I said: pass a callback delegate to BeginConnect and move all your
sending code to the delegate.
Sync:
socket.Connect(...);
socket.Send(...);
Async:
void main() {
socket.beginconnect(endpoint, mycallback, socket);
}
void mycallback(IAsyncResult result) {
Socket socket;
socket = (Socket) result.AsyncState;
socket.EndConnect(result);
socket.Send(...);
}
Best regards,
Henning Krause
}
> Sorry, meant to say BeginConnect is NOT halting my main thread in my
> service app.
[quoted text clipped - 73 lines]
>> > >> > ideas?- Hide quoted text -- Show quoted text -- Hide quoted
>> > >> > text -- Show quoted text -- Hide quoted text -- Show quoted text -
Ryan - 24 Jan 2007 18:12 GMT
Thanks Henning,
I moved my initial command (that tells the machine start sending me
data) to the connect method and thats working. Can't believe it was
that simple. However, I do want to try to reconnect if the socket
connection failed because the host didn't respond. I know that I can
put a socket.BeginConnect in my SocketException catch but my fear is
that I'll overload the stack by doing (n) socket.BeginConnect calls.
Any thoughts?
Thanks again.
On Jan 24, 11:47 am, "Henning Krause [MVP - Exchange]"
<newsgroups_rem...@this.infinitec.de> wrote:
> Of course it's not blocking your thread - that's what it's for.
>
[quoted text clipped - 101 lines]
> >> > >> > ideas?- Hide quoted text -- Show quoted text -- Hide quoted
> >> > >> > text -- Show quoted text -- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text -
Henning Krause [MVP - Exchange] - 24 Jan 2007 21:28 GMT
Hello,
no problem with stack overflows - after the BeginConnect you are leaving the
method and thereby the current stack. The next call of your delegate is on
another thread with a brand new stack :-)
Best regards,
Henning Krause
> Thanks Henning,
>
[quoted text clipped - 125 lines]
>> >> > >> > text -- Show quoted text -- Hide quoted text -- Show quoted
>> >> > >> > text -- Hide quoted text -- Show quoted text -
Mubashir Khan - 24 Jan 2007 15:27 GMT
beginconnect is your choice ... it will return in the callback function u
provide .... with the status of the connection...... call EndConnect there
to finialize async call ..... Afterwards send data if the socket has been
connected sucessfully .... otherwise another beginconnect request ......
> I'm using BeginReceive and I thought about using BeginConnect, but what
> do I need to do tell that I'm waiting for async callback. The process
[quoted text clipped - 23 lines]
>> > "re-connect" to block communication with the other machines. Any
>> > ideas?- Hide quoted text -- Show quoted text -