473,386 Members | 1,598 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,386 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.
Nov 20 '05 #1
5 2736
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]
Nov 20 '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.


Nov 20 '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]
Nov 20 '05 #4
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]
Nov 20 '05 #5
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.


Nov 20 '05 #6

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

Similar topics

4
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...
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...
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...
11
by: Grey Alien | last post by:
I am looking to write a very simple memory pool library to store only one data type at a time - i.e. to provide a contiguous block of memory to be alloc'd free'd by the calling program. I am I...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.