|
Opening a good old Port may be the solution to many a networking problem 
|
|
|
|
|
Hi all,
I have created a multi-threaded TCP/IP server. Each client connection runs in it's own thread.
The problem that I have it when I close the server and there are still clients connected. The thing is that the client threads remain active.
How can stop / dispose of the client threads so that the server can be closed for good?
Many thanks in advance
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
well you need to handle connections when you close down the server.
You should have a list of all connected clients, right?
so you will want to stop incomming connections.
then you can abort all client threads, preferable after sending information to the client about the shut down
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: You should have a list of all connected clients, right?
Yes.
musefan wrote: then you can abort all client threads
The only thing is that the client threads spawn out of another thread that is listening for any incoming connections. If a new connection is accepted by the listen thread the listen thread spawns a new thread for that connections. Thus I do not have the handle to each of the client threads that have been spawned, well I think so anyway.
Many thanks for your response
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Did you use Socket.beginAccept?
|
|
|
|
|
well you may want to change it so you store you connections somewhere you can access.
you could try using a static collection of threads. that way they can be accessed from both your connection handling thread and you main thread.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Mmmm .... yes I think that can do the trick.
Is it possible to terminate a thread if one has the thread handle?
Thanks again
Regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
I assuming its system.Threading.Thread, you can use .Abort to end the thread.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: I assuming its system.Threading.Thread
Yes.
Thanks
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Hi,
if all you need is for the server to be able to stop whenever it wants to, turn all the client-serving threads into background threads by setting their IsBackground property true. FYI: ThreadPool threads and BackgroundWorkers always are background threads, so they can't prevent your app from exiting.
however if you need to communicate with the clients about the imminent shutdown, obviously you would need to keep a list and provide the appropriate code.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: threads by setting their IsBackground property true. FYI: ThreadPool threads and BackgroundWorkers always are background threads, so they can't prevent your app from exiting.
Thank you for the information. This has helped a lot.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
You're welcome.
PS: I'd rather not look like this:
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
http://www.pastey.net/110020[^]
The following link is a simple method I created for converting a Directory based string into a compatible Dos string.
It's not working as intended;
The idea was to convert:
C:\test\test this\Example Here\Test Again\
into
c:\test\"test this"\"Example Here"\"Test Again"\
instead the code turns it into
"C:\test\test this\Example Here\Test Again\"
Please help! I'm not sure where I'm going wrong
*richTextBox1.Text += Sections[i] + "\n" + "test";* was a debug line for me.
Thanks,
Colin
modified on Thursday, March 12, 2009 7:40 AM
|
|
|
|
|
I posted an alternative unmanaged method which handles this for you automatically in your previous topic
|
|
|
|
|
Hi,
I want to store a lot of sounds in a DirectSound buffer, so how can I do that? I've tried with buffer[][] but it doesn't work. There's an error message that I have to create a new instance! I've tried with:
for(int i = 1; i <= 6; i++)
{
buffer[i][0] = new Buffer("sound/" + i.ToString() + ".wav", device);
}
I think there's no problem with the path of the sound file, because i've tested it with an normal path.
Greeting shainsen
|
|
|
|
|
what is the error and post the declaration code of that 2D array. I guess you're getting Object reference not set to an instance of an object.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Yes that's the error. Should I first declarate all the field of the array?
Greetings shainsen
|
|
|
|
|
yes
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
|
Would it not be better to use a collection of Buffer? That way you can have as many as you need without wasting memory.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
i have selected the topic "monitoring system usage " in c#.net as my 6 month project topic.please describe modules of the topics and explain the project.
|
|
|
|
|
For the love of all things good - NO!
There was a rather 'heated' discussion about this type of query yesterday and be warned, be very warned, this will not be tollerated!
This forum is for asking SPECIFIC questions regarding problems encountered writing C# CODE. It is not for frain-bucks like you to ask the same frogging question:
i have selected the topic "naval gazing" in c#.net as my 6 month project topic.please describe modules of the topics and explain the project.
Now foff!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
safeena wrote: i have selected the topic "monitoring system usage " in c#.net as my 6 month project topic.please describe modules of the topics and explain the project.
Are you some new breed of retard? This is *YOUR* project. Do the research and write the code yourself.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You suprised me. This is not the kind of JSOP reply I would expect given the doubt question.
|
|
|
|
|
i hve slected the topic "resaerch" n c#.net as my 6 mnth project please send mhe teh codz

|
|
|
|