473,387 Members | 1,619 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,387 software developers and data experts.

Handling thousands of TCP socket connections

I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not always
passed each minute so would result in a degree of threads being blocked for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...
Jul 21 '05 #1
9 2437
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a thread from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not always passed each minute so would result in a degree of threads being blocked for a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...

Jul 21 '05 #2
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginReceive use an IO Completion Port Thread? Can I simply
call this method for each and every socket I am handling on the basis it
will call the callback method using the threads in the standard threadpool
and it will only do so when data is avaiable or the socket closed?

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:4P*************@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running async-reads
on a socket by socket basis to achieve what you are talking about. The
single CPU machine I have tested on will handle 1000 concurrent
connections on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread
for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which
will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a

thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a
socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a
time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not

always
passed each minute so would result in a degree of threads being blocked

for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...



Jul 21 '05 #3
I have done some more resarch and I beleive the standard socket.BeginReceive
does use Completion Ports, but I have also seen reference to the number of
IO Completion Port threads being around 1000. Is this correct? And will this
prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look into
load balancing servers/routers to scale this further but 1000 connections
will prove a major limit very early on in the life of this project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginReceive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:4P*************@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread
for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which
will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a
thread
from a threadpool class to handle reading and logging of the data
before
returning the socket to the queue. Is it possible to identify if a
socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a
time
stamp against each socket and using this to wait until there 'should'
be
data available and then spawning a thread to read it but data is not
always
passed each minute so would result in a degree of threads being blocked
for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...



Jul 21 '05 #4
Hi Phil,

Yeah BeginRecieve does use completion ports. Unfortunatly the solution does
not scale up past the max number allowed by the ThreadPool but this is
determined by the hardware on which you are running. Look at
ThreadPool.GetMaxThreads and ThreadPool.SetMinThreads. If and when you hit
1000 concurrent users switching to a dual CPU machine should double the
number of clients you can handle.
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginReceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000. Is
this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginReceive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:4P*************@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using
.NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> I am try to evaluate the most efficient method of handling thousands
> of
> simultaneous TCP connects each of which remain connected to the server
> for
> hours and pass a small amount of data usually once a minute. The data
> received is logged in a SQL Server database.
>
> The only method I have found of reading each socket requires a thread
> for
> each connection which blocks waiting for data. This appears to be very
> inefficient as it will result in thousands of threads, each of which
> will
> have a networkstream and reader object doing very little. Is this
> blocking
> method the best/only method of reading data from a TCP socket?
>
> I was thinking of implementing a queue of open sockets which I cycled
> through checking if each had any data ready to handle, spawning off a
thread
> from a threadpool class to handle reading and logging of the data
> before
> returning the socket to the queue. Is it possible to identify if a
> socket
> has data ready to be read and how many bytes to read to prevent it
> from
> blocking?
>
> I can possibly do an inefficient variation of the above by keeping a
> time
> stamp against each socket and using this to wait until there 'should'
> be
> data available and then spawning a thread to read it but data is not
always
> passed each minute so would result in a degree of threads being
> blocked
for
> a duration.
>
> Does anybody have a suggestion as to the best method?
>
> Thanks
>
> Phil...
>
>



Jul 21 '05 #5
Thanks for the information this has helped point me in a good direction to
evaluate further.

As I can "almost" anticipate when data will be available (because it comes
once a minute or somtime after) I may be able to delay initiating each
subesquent BeginReceive by a minute thus the number of pending reads at any
point in time will be considerably less, increasing the capacity
significatntly passed the thread limitation. It will probably be run on a
Quad Xeon server ultimatly

Thanks for the ideas.

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:m5**************@newsfe6-win.ntli.net...
Hi Phil,

Yeah BeginRecieve does use completion ports. Unfortunatly the solution
does not scale up past the max number allowed by the ThreadPool but this
is determined by the hardware on which you are running. Look at
ThreadPool.GetMaxThreads and ThreadPool.SetMinThreads. If and when you hit
1000 concurrent users switching to a dual CPU machine should double the
number of clients you can handle.
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginReceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000.
Is this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I
am after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginReceive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:4P*************@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
> Check out the static method Socket.Select() (assuming you are using
> .NET
> framework).
>
> Mike
>
>
> "Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> I am try to evaluate the most efficient method of handling thousands
>> of
>> simultaneous TCP connects each of which remain connected to the
>> server for
>> hours and pass a small amount of data usually once a minute. The data
>> received is logged in a SQL Server database.
>>
>> The only method I have found of reading each socket requires a thread
>> for
>> each connection which blocks waiting for data. This appears to be
>> very
>> inefficient as it will result in thousands of threads, each of which
>> will
>> have a networkstream and reader object doing very little. Is this
>> blocking
>> method the best/only method of reading data from a TCP socket?
>>
>> I was thinking of implementing a queue of open sockets which I cycled
>> through checking if each had any data ready to handle, spawning off a
> thread
>> from a threadpool class to handle reading and logging of the data
>> before
>> returning the socket to the queue. Is it possible to identify if a
>> socket
>> has data ready to be read and how many bytes to read to prevent it
>> from
>> blocking?
>>
>> I can possibly do an inefficient variation of the above by keeping a
>> time
>> stamp against each socket and using this to wait until there 'should'
>> be
>> data available and then spawning a thread to read it but data is not
> always
>> passed each minute so would result in a degree of threads being
>> blocked
> for
>> a duration.
>>
>> Does anybody have a suggestion as to the best method?
>>
>> Thanks
>>
>> Phil...
>>
>>
>
>



Jul 21 '05 #6
Note that with the current version of the CLR you have a max of 1000 IOCP
threads per CPU in the pool.

Willy.

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginReceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000. Is
this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I am
after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginReceive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:4P*************@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using
.NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
> I am try to evaluate the most efficient method of handling thousands
> of
> simultaneous TCP connects each of which remain connected to the server
> for
> hours and pass a small amount of data usually once a minute. The data
> received is logged in a SQL Server database.
>
> The only method I have found of reading each socket requires a thread
> for
> each connection which blocks waiting for data. This appears to be very
> inefficient as it will result in thousands of threads, each of which
> will
> have a networkstream and reader object doing very little. Is this
> blocking
> method the best/only method of reading data from a TCP socket?
>
> I was thinking of implementing a queue of open sockets which I cycled
> through checking if each had any data ready to handle, spawning off a
thread
> from a threadpool class to handle reading and logging of the data
> before
> returning the socket to the queue. Is it possible to identify if a
> socket
> has data ready to be read and how many bytes to read to prevent it
> from
> blocking?
>
> I can possibly do an inefficient variation of the above by keeping a
> time
> stamp against each socket and using this to wait until there 'should'
> be
> data available and then spawning a thread to read it but data is not
always
> passed each minute so would result in a degree of threads being
> blocked
for
> a duration.
>
> Does anybody have a suggestion as to the best method?
>
> Thanks
>
> Phil...
>
>



Jul 21 '05 #7
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl...
Note that with the current version of the CLR you have a max of 1000 IOCP
threads per CPU in the pool.
I don't understand what you mean. An IOCP isn't a thread. What is this
1000 limit? Does the CLR create a new thread for every 1000 objects sharing
an IOCP? I understand IOCPs and I understand that the CLR uses them but,
I'm not quite sure how the CLR uses them or what this limit of 1000 is.

Willy.

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:e2**************@TK2MSFTNGP14.phx.gbl...
I have done some more resarch and I beleive the standard
socket.BeginReceive does use Completion Ports, but I have also seen
reference to the number of IO Completion Port threads being around 1000.
Is this correct? And will this prevent scaling above 1000 sockets?

Whilst this wont be an imediate problem we could well get into 10-100
thoushand connections in the future. At a cerain point we will be look
into load balancing servers/routers to scale this further but 1000
connections will prove a major limit very early on in the life of this
project.

Thanks

Phil...

"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
Thank you both for your suggestions, both seem to offer the solution I
am after.

I am particaulr interested in the IO Completion port threads. Does the
standard socket.BeginReceive use an IO Completion Port Thread? Can I
simply call this method for each and every socket I am handling on the
basis it will call the callback method using the threads in the standard
threadpool and it will only do so when data is avaiable or the socket
closed?

Phil...
"Stelrad Doulton" <___@____.com> wrote in message
news:4P*************@newsfe1-gui.ntli.net...
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running
async-reads on a socket by socket basis to achieve what you are talking
about. The single CPU machine I have tested on will handle 1000
concurrent connections on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
> Check out the static method Socket.Select() (assuming you are using
> .NET
> framework).
>
> Mike
>
>
> "Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
> news:%2****************@TK2MSFTNGP15.phx.gbl...
>> I am try to evaluate the most efficient method of handling thousands
>> of
>> simultaneous TCP connects each of which remain connected to the
>> server for
>> hours and pass a small amount of data usually once a minute. The data
>> received is logged in a SQL Server database.
>>
>> The only method I have found of reading each socket requires a thread
>> for
>> each connection which blocks waiting for data. This appears to be
>> very
>> inefficient as it will result in thousands of threads, each of which
>> will
>> have a networkstream and reader object doing very little. Is this
>> blocking
>> method the best/only method of reading data from a TCP socket?
>>
>> I was thinking of implementing a queue of open sockets which I cycled
>> through checking if each had any data ready to handle, spawning off a
> thread
>> from a threadpool class to handle reading and logging of the data
>> before
>> returning the socket to the queue. Is it possible to identify if a
>> socket
>> has data ready to be read and how many bytes to read to prevent it
>> from
>> blocking?
>>
>> I can possibly do an inefficient variation of the above by keeping a
>> time
>> stamp against each socket and using this to wait until there 'should'
>> be
>> data available and then spawning a thread to read it but data is not
> always
>> passed each minute so would result in a degree of threads being
>> blocked
> for
>> a duration.
>>
>> Does anybody have a suggestion as to the best method?
>>
>> Thanks
>>
>> Phil...
>>
>>
>
>



Jul 21 '05 #8
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running async-reads
on a socket by socket basis to achieve what you are talking about. The
single CPU machine I have tested on will handle 1000 concurrent connections
on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a

thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not

always
passed each minute so would result in a degree of threads being blocked

for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...


Nov 22 '05 #9
In addition to looking at Socket.Select, have another look at the
ThreadPool. You will find that there are 2 types of thread that it will
service; worker threads and IO completion port threads. I have recently
finished a thread-per-client server app that uses long running async-reads
on a socket by socket basis to achieve what you are talking about. The
single CPU machine I have tested on will handle 1000 concurrent connections
on that basis.
"Mike Jansen" <mj**********@mail.com> wrote in message
news:uB**************@TK2MSFTNGP15.phx.gbl...
Check out the static method Socket.Select() (assuming you are using .NET
framework).

Mike
"Phil Jenson" <ph**@jenson.co.uk.nospam> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am try to evaluate the most efficient method of handling thousands of
simultaneous TCP connects each of which remain connected to the server
for
hours and pass a small amount of data usually once a minute. The data
received is logged in a SQL Server database.

The only method I have found of reading each socket requires a thread for
each connection which blocks waiting for data. This appears to be very
inefficient as it will result in thousands of threads, each of which will
have a networkstream and reader object doing very little. Is this
blocking
method the best/only method of reading data from a TCP socket?

I was thinking of implementing a queue of open sockets which I cycled
through checking if each had any data ready to handle, spawning off a

thread
from a threadpool class to handle reading and logging of the data before
returning the socket to the queue. Is it possible to identify if a socket
has data ready to be read and how many bytes to read to prevent it from
blocking?

I can possibly do an inefficient variation of the above by keeping a time
stamp against each socket and using this to wait until there 'should' be
data available and then spawning a thread to read it but data is not

always
passed each minute so would result in a degree of threads being blocked

for
a duration.

Does anybody have a suggestion as to the best method?

Thanks

Phil...


Nov 22 '05 #10

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

Similar topics

4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
12
by: Phil Jenson | last post by:
I am try to evaluate the most efficient method of handling thousands of simultaneous TCP connects each of which remain connected to the server for hours and pass a small amount of data usually once...
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
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.