Asynchronous socket server

G

Guest

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
 
W

William Stacey [MVP]

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]

|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
 
G

Guest

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
 
W

William Stacey [MVP]

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]

| 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]
| >
| > | > |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
| >
| >
| >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top