471,596 Members | 795 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Asynchronous socket server

I am writing an application that uses asynchronous sockets to get data over
ethernet from embedded devices, up to 30 concurrent devices.(These devices
are written in C).

My application implements an asychronous socket server while the embedded
devices are the clients

When the data comes in over the socket it is eventually passed into a
message queue.

A separate thread in the app is responsible for taking the data off of the
queue and then processing it.

This thread and/or others will need to be able to send data back to the
distributed embedded devices.

The problem i am having is how to achieve this. I'm not sure how these
threads can pass data to or communicate with the asynchonous socket server to
send data back to the clients.

The MSDN example has the socket server immediately sending data back to all
clients connected to it. (App is a chat spplication)

This is not what i want to do though as I have explained above.

I know there socket server has an asychronous send method. Do i use this
some way? If so how do I use it with the other threads in my app?

I'd appreciate any advice that anyone could give me.
Thanks In Advance
Macca
Feb 11 '06 #1
4 2592
Hi Macca,

don't have a direct answer, but I always liked the Indy Sockets library
for Delphi to simplify building network client/servers:

http://www.indyproject.org/Sockets/index.en.iwp

There's a .NET version now, but have never used it yet.

Regards,

Wiebe Tijsma

Macca wrote:
I am writing an application that uses asynchronous sockets to get data over
ethernet from embedded devices, up to 30 concurrent devices.(These devices
are written in C).

My application implements an asychronous socket server while the embedded
devices are the clients

When the data comes in over the socket it is eventually passed into a
message queue.

A separate thread in the app is responsible for taking the data off of the
queue and then processing it.

This thread and/or others will need to be able to send data back to the
distributed embedded devices.

The problem i am having is how to achieve this. I'm not sure how these
threads can pass data to or communicate with the asynchonous socket server to
send data back to the clients.

The MSDN example has the socket server immediately sending data back to all
clients connected to it. (App is a chat spplication)

This is not what i want to do though as I have explained above.

I know there socket server has an asychronous send method. Do i use this
some way? If so how do I use it with the other threads in my app?

I'd appreciate any advice that anyone could give me.
Thanks In Advance
Macca

Feb 11 '06 #2
For 30 devices you don't really need the added complication of async
processing.
1) Create a listener thread the accepts connection.
2) Create a new thread (i.e. WorkerObject) for each connection and pass it
the TcpClient.
3) The thread will handle reads and write syncronously and quit.

In this way, you don't even need the queue or locking on it. If you like
the queue, a neat way to do this would be a UserThreadPool with some max 30
workers. Then just queue the TcpClients to the thread pool and each TP
thread will handle the end-to-end conversation with the client and quit -
ready to handle the next item in the queue.

--
William Stacey [MVP]

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
|I am writing an application that uses asynchronous sockets to get data over
| ethernet from embedded devices, up to 30 concurrent devices.(These devices
| are written in C).
|
| My application implements an asychronous socket server while the embedded
| devices are the clients
|
| When the data comes in over the socket it is eventually passed into a
| message queue.
|
| A separate thread in the app is responsible for taking the data off of the
| queue and then processing it.
|
| This thread and/or others will need to be able to send data back to the
| distributed embedded devices.
|
| The problem i am having is how to achieve this. I'm not sure how these
| threads can pass data to or communicate with the asynchonous socket server
to
| send data back to the clients.
|
| The MSDN example has the socket server immediately sending data back to
all
| clients connected to it. (App is a chat spplication)
|
| This is not what i want to do though as I have explained above.
|
| I know there socket server has an asychronous send method. Do i use this
| some way? If so how do I use it with the other threads in my app?
|
| I'd appreciate any advice that anyone could give me.
|
|
| Thanks In Advance
| Macca
Feb 13 '06 #3
Hi William,

Thanks for the advice. I've been told to use asynchronous sockets as the
code already exists. I would appreciate it if you can tell me how other
threads in the app could communicate with asynchronous sockets?

Thanks
Macca

"William Stacey [MVP]" wrote:
For 30 devices you don't really need the added complication of async
processing.
1) Create a listener thread the accepts connection.
2) Create a new thread (i.e. WorkerObject) for each connection and pass it
the TcpClient.
3) The thread will handle reads and write syncronously and quit.

In this way, you don't even need the queue or locking on it. If you like
the queue, a neat way to do this would be a UserThreadPool with some max 30
workers. Then just queue the TcpClients to the thread pool and each TP
thread will handle the end-to-end conversation with the client and quit -
ready to handle the next item in the queue.

--
William Stacey [MVP]

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
|I am writing an application that uses asynchronous sockets to get data over
| ethernet from embedded devices, up to 30 concurrent devices.(These devices
| are written in C).
|
| My application implements an asychronous socket server while the embedded
| devices are the clients
|
| When the data comes in over the socket it is eventually passed into a
| message queue.
|
| A separate thread in the app is responsible for taking the data off of the
| queue and then processing it.
|
| This thread and/or others will need to be able to send data back to the
| distributed embedded devices.
|
| The problem i am having is how to achieve this. I'm not sure how these
| threads can pass data to or communicate with the asynchonous socket server
to
| send data back to the clients.
|
| The MSDN example has the socket server immediately sending data back to
all
| clients connected to it. (App is a chat spplication)
|
| This is not what i want to do though as I have explained above.
|
| I know there socket server has an asychronous send method. Do i use this
| some way? If so how do I use it with the other threads in my app?
|
| I'd appreciate any advice that anyone could give me.
|
|
| Thanks In Advance
| Macca

Feb 17 '06 #4
Not sure I know what you mean. async server logic can get very complicated
and can not give you a one size fits all answer. It all depends on your
code and what your doing. How many clients will be connected at one time?
You may want to using a work crew sync server instead as it is much easier
to code correctly.

--
William Stacey [MVP]

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.com...
| Hi William,
|
| Thanks for the advice. I've been told to use asynchronous sockets as the
| code already exists. I would appreciate it if you can tell me how other
| threads in the app could communicate with asynchronous sockets?
|
| Thanks
| Macca
|
| "William Stacey [MVP]" wrote:
|
| > For 30 devices you don't really need the added complication of async
| > processing.
| > 1) Create a listener thread the accepts connection.
| > 2) Create a new thread (i.e. WorkerObject) for each connection and pass
it
| > the TcpClient.
| > 3) The thread will handle reads and write syncronously and quit.
| >
| > In this way, you don't even need the queue or locking on it. If you
like
| > the queue, a neat way to do this would be a UserThreadPool with some max
30
| > workers. Then just queue the TcpClients to the thread pool and each TP
| > thread will handle the end-to-end conversation with the client and
quit -
| > ready to handle the next item in the queue.
| >
| > --
| > William Stacey [MVP]
| >
| > "Macca" <Ma***@discussions.microsoft.com> wrote in message
| > news:3E**********************************@microsof t.com...
| > |I am writing an application that uses asynchronous sockets to get data
over
| > | ethernet from embedded devices, up to 30 concurrent devices.(These
devices
| > | are written in C).
| > |
| > | My application implements an asychronous socket server while the
embedded
| > | devices are the clients
| > |
| > | When the data comes in over the socket it is eventually passed into a
| > | message queue.
| > |
| > | A separate thread in the app is responsible for taking the data off of
the
| > | queue and then processing it.
| > |
| > | This thread and/or others will need to be able to send data back to
the
| > | distributed embedded devices.
| > |
| > | The problem i am having is how to achieve this. I'm not sure how these
| > | threads can pass data to or communicate with the asynchonous socket
server
| > to
| > | send data back to the clients.
| > |
| > | The MSDN example has the socket server immediately sending data back
to
| > all
| > | clients connected to it. (App is a chat spplication)
| > |
| > | This is not what i want to do though as I have explained above.
| > |
| > | I know there socket server has an asychronous send method. Do i use
this
| > | some way? If so how do I use it with the other threads in my app?
| > |
| > | I'd appreciate any advice that anyone could give me.
| > |
| > |
| > | Thanks In Advance
| > | Macca
| >
| >
| >
Feb 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Corne Oosthuizen | last post: by
5 posts views Thread by Droopy Toon | last post: by
7 posts views Thread by Colin | last post: by
reply views Thread by Macca | last post: by
4 posts views Thread by Engineerik | last post: by
2 posts views Thread by Nicolas Le Gland | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.