473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to pool on socket ?

Hi,

How do I pool my socket to see if there is any message pending?

I don't want to use timers because they are multithreaded and it break
the linearity of my messages. (incoming message are numbered and it is
important to keep the order)

Can I add a handler to the socket? So it could react by itself when
there is pending data? Something like that the winsock (in VB6) was doing.

Thank you.
Jul 21 '05 #1
4 1704
In article <dcaOc.118392$Rf.22568@edtnps84>, User wrote:
Hi,

How do I pool my socket to see if there is any message pending?

I don't want to use timers because they are multithreaded and it break
the linearity of my messages. (incoming message are numbered and it is
important to keep the order)

Can I add a handler to the socket? So it could react by itself when
there is pending data? Something like that the winsock (in VB6) was doing.

Thank you.


The absolute best way to do this would most likely be to use the asnyc
methods of the socket class (BeginXXXX). The socket will then fire a
callback when data is received.

You could also use the Poll method on the socket to determine if there
is data. You can also use Socket.Select along with Receive with the
Peek flag to determine the socket state...

There are a number of ways that you can accomplish what you're asking,
but the Asnyc methods are usually the most efficient.
--
Tom Shelton [MVP]
Jul 21 '05 #2
Thank you Tom,

I have another question. I haven't use this async socket yet, but I'll
read on it. Right now, I am using a timer control to pool over the
socket.pending to see if there is new data to process. The timer is
running all day long.

Does the async socket, once started, will pool the socket as long as it
is not stopped? I mean, I start it once and will run as the same way I
am using the timer control right now?

Thank you.

Tom Shelton wrote:
In article <dcaOc.118392$Rf.22568@edtnps84>, User wrote:
Hi,

How do I pool my socket to see if there is any message pending?

I don't want to use timers because they are multithreaded and it break
the linearity of my messages. (incoming message are numbered and it is
important to keep the order)

Can I add a handler to the socket? So it could react by itself when
there is pending data? Something like that the winsock (in VB6) was doing.

Thank you.

The absolute best way to do this would most likely be to use the asnyc
methods of the socket class (BeginXXXX). The socket will then fire a
callback when data is received.

You could also use the Poll method on the socket to determine if there
is data. You can also use Socket.Select along with Receive with the
Peek flag to determine the socket state...

There are a number of ways that you can accomplish what you're asking,
but the Asnyc methods are usually the most efficient.


Jul 21 '05 #3
On Fri, 30 Jul 2004 12:36:13 GMT, User wrote:
Thank you Tom,

I have another question. I haven't use this async socket yet, but I'll
read on it. Right now, I am using a timer control to pool over the
socket.pending to see if there is new data to process. The timer is
running all day long.

Does the async socket, once started, will pool the socket as long as it
is not stopped? I mean, I start it once and will run as the same way I
am using the timer control right now?

Thank you.


Basically, once you begin the async operation, it will continue until the
socket is closed - or the call back is fired. Once it is fired, you need
to call the async method again... So just for a quick psuedo code example:

begin serverfunc
socket.bind
socket.listen
while (running)
manualresetevent.reset
socket.beginaccept
manualresetevent.waitone
wend
end serverfunc
begin acceptfunc
' get socket object
client = get_from_async_object

' signal server thread to continue
manualresetevent.set

client.beginread
end acceptfunc

begin readfunc
' do read stuff

' send a reply
client.beginsend
end readfunc

begin sendfunc
if sent client.beginread
end sendfunc

etc, etc...

There are some good articles on msdn (this should get you in the correct
location):

http://msdn.microsoft.com/library/de...rverSocket.asp

There is a little more code involved in using the async methods, but they
are the most scalable and efficient.

--
Tom Shelton [MVP]
Jul 21 '05 #4
That is very interesting Tom, I red the article on MSDN, I got to use it.

Thank you very much.

Tom Shelton wrote:
On Fri, 30 Jul 2004 12:36:13 GMT, User wrote:

Thank you Tom,

I have another question. I haven't use this async socket yet, but I'll
read on it. Right now, I am using a timer control to pool over the
socket.pending to see if there is new data to process. The timer is
running all day long.

Does the async socket, once started, will pool the socket as long as it
is not stopped? I mean, I start it once and will run as the same way I
am using the timer control right now?

Thank you.

Basically, once you begin the async operation, it will continue until the
socket is closed - or the call back is fired. Once it is fired, you need
to call the async method again... So just for a quick psuedo code example:

begin serverfunc
socket.bind
socket.listen
while (running)
manualresetevent.reset
socket.beginaccept
manualresetevent.waitone
wend
end serverfunc
begin acceptfunc
' get socket object
client = get_from_async_object

' signal server thread to continue
manualresetevent.set

client.beginread
end acceptfunc

begin readfunc
' do read stuff

' send a reply
client.beginsend
end readfunc

begin sendfunc
if sent client.beginread
end sendfunc

etc, etc...

There are some good articles on msdn (this should get you in the correct
location):

http://msdn.microsoft.com/library/de...rverSocket.asp

There is a little more code involved in using the async methods, but they
are the most scalable and efficient.


Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kieran Benton | last post by:
Hello, I'm currently in the tail end process of developing a high scalability server for my employer. Essentially it receives short socket based connections with an ASCII message, parses that...
5
by: david.kao | last post by:
Hi All: I am creating a COM+ Pool object in C#. I set up the following attributes: JIT (true),Pool size; and at the end of each public method I called ContextUtil.DeactivateOnReturn=true to set...
9
by: Abhishek Srivastava | last post by:
Hello All, In IIS 6.0 We have a concept of worker processes and application pools. As I understand it, we can have multiple worker process per appliction pool. Each worker process is dedicated...
5
by: User | last post by:
Hi, How do I pool my socket to see if there is any message pending? I don't want to use timers because they are multithreaded and it break the linearity of my messages. (incoming message are...
1
by: Lee Greco | last post by:
I'm looking for some advice on how to proceed. Here's the scenario: I've got to develop a high availability VB.Net web service that basically acts as a middle man between the web service...
2
by: JoeSep | last post by:
Hi! Is it correct/safe to define a connection pool in the string "sqlConnectionString" of the "sessionState" section of Web.config? - The application is developed using AspNet 1.1 in a Windows...
0
by: roni schuetz | last post by:
since a few day's i'm running around the problem that I stocked with a change i need to do. hopefully somebody here can give me a tipp which will be usefull to solve my problem. I'm using a...
5
by: mackenzie | last post by:
Hello, I am looking for a little bit of help. I am trying to create a dynamically allocated object which contains one or more objects of type boost::pool<>. I get a compiler error when an object...
23
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, Recently I had a new coworker. There is some dispute between us. The last company he worked for has a special networking programming model. They split the business logic into...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.