473,624 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2758
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***@discussi ons.microsoft.c om> wrote in message
news:3E******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:3E******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:B8******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
| > news:3E******** *************** ***********@mic rosoft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2809
by: Corne Oosthuizen | last post by:
I'm writing a Telnet Server application using Asynchronous sockets. I spawn a listener thread to handel incomming connections and create a separate client socket for each new connection. I then set the new client socket to BeginReceive(). My problem: When two client socket connections send data
5
6016
by: Droopy Toon | last post by:
Hi, I am using asynchronous socket (BeginAccept for example). I tried to name each thread I am using but threads created by asynchronous Socket functions (like BeginAccept) creates "anonymous" threads. I named the thread (see sample code below) in Accept callback started by BeginAccept but all connections accepted run in a thread that has the same name ! So, even a new thread is not started by BeginAccept, even my naming is
7
2377
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew what they were doing could take a look at my code and tell me where and why I'm going wrong. Any suggestions of groups or forums?
2
6868
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 there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server" app. I am using the standard asynch socket code from MSDN to listen for connections and they...
0
4670
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 number of different types of data coming in. I have a databuffer for each type of data coming in.
4
3598
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 client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
6
6991
by: Pat B | last post by:
Hi, I'm writing my own implementation of the Gnutella P2P protocol using C#. I have implemented it using BeginReceive and EndReceive calls so as not to block when waiting for data from the supernode. Everything I have written works fine sending and receiving uncompressed data. But now I want to implement compression using the deflate algorithm as the Gnutella protocol accepts: Accept-Encoding: deflate Content-Encoding: deflate in the...
2
3417
by: Nicolas Le Gland | last post by:
Hello everyone here. This is my first post in this newsgroup, I hope I won't be to much off-topic. Feel free to redirect me to any better group. I am getting strange timing issues when failing to asynchronously connect sockets on closed or filtered ports, but I'm quite unsure if this is a PHP issue or my misunderstanding, as it seems that socket streams only wrap around <sys/socket.h>.
1
7155
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN site, which is actually for sending strings. I tried to adapt this code so that the client sends an image instead of a string. However, there is something wrong on the server side (i guess)... The server starts listening, the client starts sending...
0
8170
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.