Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by SVC
Tue, 11 Jul 2006 20:58
Event driven receive
Author: SVC
Date: Tue, 11 Jul 2006 20:58
Date: Tue, 11 Jul 2006 20:58
18 lines
1469 bytes
1469 bytes
Have written a socket program that works fine but would like to make it more
efficient (faster).
Basically, I'm using:
- Starting to socket (WSAStartup (MAKEWORD(1,1), &WSAData))
- Connecting it (connect (..))
- Sending (send(..))
- Receiving (recv(...))
- Closing
The problem is the receiving! Every time I call recv(...), it seems like the
server (black box) is slowing down.
Is there a way to make solely the Receiving process event driven without
altering the whole program?
Tx,
S.
Re: Event driven receive
Author: Remy Lebeau (TeamB)
Date: Tue, 11 Jul 2006 22:22
Date: Tue, 11 Jul 2006 22:22
29 lines
2333 bytes
2333 bytes
"SVC" <svchamlian@hotmail.com> wrote in message news:44b41065$1@newsgroups.borland.com... > The problem is the receiving! Every time I call recv(...), it > seems like the server (black box) is slowing down. Reading from a socket, especially if you do it often, should not be slowing the server down at all. On the other hand, if you are not reading very often, that could, especially if the server is using sockets in blocking mode on its end. > Is there a way to make solely the Receiving process event > driven without altering the whole program? You can use ioctlsocket() to put the socket into non-blocking mode. But keep in mind that doing so will greatly alter the behavior of your code. If your code is currently written to expect blocking operations, then you will have to re-write it in order to handle the socket events. Not only for reading but for writing as well. You need to use WSAAsyncSelect() or WSAEventSelect() to receive the actual events, and the logic of your socket management will be split up considerably because of the event handling. When reading, you will have to buffer all incoming data, if you are not already doing so, in order to ensure that you do not lose data between events. When writing, if the socket becomes blocked, then you have to wait for an event to be triggered before you can write more data again. Gambit
Re: Event driven receive
Author: SVC
Date: Wed, 12 Jul 2006 16:08
Date: Wed, 12 Jul 2006 16:08
49 lines
2759 bytes
2759 bytes
My socket is non-blocking though I have no idea of the server's socket mode of operation. Is it possible to use the WSAAsyncSelect() in a console application (i.e., no window handle available, my communication module is a thread running in the background)? S. "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:44b424b9$1@newsgroups.borland.com... > > "SVC" <svchamlian@hotmail.com> wrote in message > news:44b41065$1@newsgroups.borland.com... > > > The problem is the receiving! Every time I call recv(...), it > > seems like the server (black box) is slowing down. > > Reading from a socket, especially if you do it often, should not be slowing > the server down at all. On the other hand, if you are not reading very > often, that could, especially if the server is using sockets in blocking > mode on its end. > > > Is there a way to make solely the Receiving process event > > driven without altering the whole program? > > You can use ioctlsocket() to put the socket into non-blocking mode. But > keep in mind that doing so will greatly alter the behavior of your code. If > your code is currently written to expect blocking operations, then you will > have to re-write it in order to handle the socket events. Not only for > reading but for writing as well. You need to use WSAAsyncSelect() or > WSAEventSelect() to receive the actual events, and the logic of your socket > management will be split up considerably because of the event handling. > When reading, you will have to buffer all incoming data, if you are not > already doing so, in order to ensure that you do not lose data between > events. When writing, if the socket becomes blocked, then you have to wait > for an event to be triggered before you can write more data again. > > > Gambit > >
Re: Event driven receive
Author: Remy Lebeau (TeamB)
Date: Wed, 12 Jul 2006 16:54
Date: Wed, 12 Jul 2006 16:54
25 lines
1781 bytes
1781 bytes
"SVC" <svchamlian@hotmail.com> wrote in message news:44b51e08@newsgroups.borland.com... > My socket is non-blocking Sockets are blocking by default. You have to explicitally put them into non-blocking mode in your code. You did not describe doing that step in the sequence of operations that you posted earlier. > Is it possible to use the WSAAsyncSelect() in a console application Yes, but you will need to implement a message queue in your code in order for it to work. Non-blocking sockets are message-based objects, regardless of whether you use a window or an event object to receive notifications of socket events. > my communication module is a thread running in the background I do not recommend using a non-blocking socket in a worker thread if you can avoid it. That will complicate the thread's design. Blocking sockets work better. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads