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

Asynchronous socket and thread name

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
wrong.

Thanks in advance for your help.
code:

...
Socket server = new Socket (AddressFamily.InterNetwork,
SocketType.Stream, Protocol.Tcp);
...
server.BeginAccept (new AsyncCallback (AcceptConnection), server);
...

void AcceptConnection (IAsynResult iar)
{
Socket server = (Socket) iar.AsyncState;
Socket client = server.EndAccept (iar);
Thread.CurrentThread.Name = "TCP Accepted on #" +
client.RemoteEndPoint.ToString ()
...
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 5994
The thread running your callback is a thread pool thread. So it could be
the same thread pool thread each time or a different one depending on how
the thread pool threads are being used by the application. So naming the
thread has not much value I think. Moreover, IMO, I don't find using async
Accept very usefull. I would just do accepts on a dedicated thread in your
server listen loop. Then use async reads and writes if you want.

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Droopy Toon" <dr********@ibelgique.com> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
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
wrong.

Thanks in advance for your help.
code:

..
Socket server = new Socket (AddressFamily.InterNetwork,
SocketType.Stream, Protocol.Tcp);
..
server.BeginAccept (new AsyncCallback (AcceptConnection), server);
..

void AcceptConnection (IAsynResult iar)
{
Socket server = (Socket) iar.AsyncState;
Socket client = server.EndAccept (iar);
Thread.CurrentThread.Name = "TCP Accepted on #" +
client.RemoteEndPoint.ToString ()
..
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #2
Moreover, IMO, I don't find using async
Accept very usefull. I would just do accepts on a dedicated thread in
your
server listen loop. That's right, it gives also better berformance.
Async doesn't mean that all the time you get best performance, always check
speeds and use sync and async in mixed mode.
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:em**************@TK2MSFTNGP12.phx.gbl... The thread running your callback is a thread pool thread. So it could be
the same thread pool thread each time or a different one depending on how
the thread pool threads are being used by the application. So naming the
thread has not much value I think. Moreover, IMO, I don't find using
async
Accept very usefull. I would just do accepts on a dedicated thread in
your
server listen loop. Then use async reads and writes if you want.

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Droopy Toon" <dr********@ibelgique.com> wrote in message
news:eK**************@TK2MSFTNGP11.phx.gbl...
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
wrong.

Thanks in advance for your help.
code:

..
Socket server = new Socket (AddressFamily.InterNetwork,
SocketType.Stream, Protocol.Tcp);
..
server.BeginAccept (new AsyncCallback (AcceptConnection), server);
..

void AcceptConnection (IAsynResult iar)
{
Socket server = (Socket) iar.AsyncState;
Socket client = server.EndAccept (iar);
Thread.CurrentThread.Name = "TCP Accepted on #" +
client.RemoteEndPoint.ToString ()
..
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3
OK I understand.
I should have very few concurrent connections so may be I should not use
async mode and handle all threads by myself.
So, I can name all threads.
I named my threads because my logging is prefixed with the time and the
thread name.

Thanks a lot for your help and best wishes for the year 2005.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

Why you need to name threads ?
I should have very few concurrent connections In normal desktop pc it can be 50 - 100.

For good exmple code about socket see www.lumisoft.ee mailserver project.
It uses mixed mode sockets, has simple(as possible) well commented c# source
code.

"Droopy Toon" <dr********@ibelgique.com> wrote in message
news:eZ**************@TK2MSFTNGP14.phx.gbl... OK I understand.
I should have very few concurrent connections so may be I should not use
async mode and handle all threads by myself.
So, I can name all threads.
I named my threads because my logging is prefixed with the time and the
thread name.

Thanks a lot for your help and best wishes for the year 2005.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #5
OK thanks I will have a look at this project.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

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

Similar topics

6
by: Zunbeltz Izaola | last post by:
Hi, I have the following problem. I'm developing a GUI program (wxPython). This program has to comunicate (TCP) whit other program that controls a laboratory machine to do a measurement. I...
0
by: Richard | last post by:
Hi, I'm suffering a socket race condition - I think. The code works fine at full speed on a single CPU machine. However when I run full speed on a 2 Zeon machine the socket drops data on an...
7
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...
4
by: taskswap | last post by:
I have a legacy application written in C that I'm trying to convert to C#. It processes a very large amount of data from many clients (actually, upstream servers - this is a mux) simultaneously. ...
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...
6
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.