Click here to Skip to main content
16,005,491 members
Home / Discussions / C#
   

C#

 
QuestionCreate a Folder Pin
T4AMD6-Nov-07 8:50
T4AMD6-Nov-07 8:50 
AnswerRe: Create a Folder Pin
Christian Graus6-Nov-07 9:43
protectorChristian Graus6-Nov-07 9:43 
QuestionRe: Create a Folder Pin
T4AMD6-Nov-07 10:46
T4AMD6-Nov-07 10:46 
QuestionDateTimePicker value format Pin
JMaior6-Nov-07 8:39
JMaior6-Nov-07 8:39 
QuestionInaccesible in CD of setup Pin
mehrdadc486-Nov-07 8:38
mehrdadc486-Nov-07 8:38 
AnswerRe: Inaccesible in CD of setup Pin
snorkie6-Nov-07 9:19
professionalsnorkie6-Nov-07 9:19 
Questionprevious and next buttons in DataList using C#.Net Pin
cwah6-Nov-07 8:16
cwah6-Nov-07 8:16 
QuestionClient/Server Disconnection Pin
jlgeris6-Nov-07 7:48
jlgeris6-Nov-07 7:48 
I have a fairly simple client/server structure using System.Net.Sockets, where the server only sends data to a collection of clients, and the clients only receive data, so, the data flow is unidirectional. My server sends the same data to each of the connected clients, at the same time through a for loop. The loop sends the data, or removes the client if it has disconnected. My problem is when the client disconnects, it can cause the server program to pause.

This is where the server distributes the data:

<br />
      for (int i = Clients.Count - 1; i >= 0; i--)<br />
                  {<br />
                      if (((Client)Clients[i]).isAlive() && serve)<br />
                      {<br />
                          ((Client)Clients[i]).send(data.get_bytes());<br />
                      }<br />
                      else<br />
                      {<br />
                          ((Client)Clients[i]).Stop();  // releases resources associated w/ client<br />
                          Clients.RemoveAt(i);<br />
                      }<br />


Also in the server code, there is a client handling class, and this is the send function used above:

<br />
      try<br />
                      {<br />
                          ns.Write(sendB, 0, sendB.Length);<br />
                      }<br />
                      catch (***Exception) { } //if there's an error i will say that the client has disconnected, and isAlive = false;<br />
<br />


I would like to keep it simple and have the client disconnect, whether or not the client disconnected on purpose, or the connection is cut. The actual client code is simple, and just sits in a loop waiting to call the NetworkStream read() call. I'm sure there's a better and more efficient way of handling the client disconnecting, b/c i don't want this to affect the remaining clients, if one disconnects for any reason. Any ideas? Thanks.
AnswerRe: Client/Server Disconnection Pin
Ennis Ray Lynch, Jr.6-Nov-07 8:09
Ennis Ray Lynch, Jr.6-Nov-07 8:09 
GeneralRe: Client/Server Disconnection Pin
jlgeris6-Nov-07 8:33
jlgeris6-Nov-07 8:33 
QuestionRe-use code Pin
simsen6-Nov-07 7:28
simsen6-Nov-07 7:28 
AnswerRe: Re-use code Pin
half-life6-Nov-07 7:42
half-life6-Nov-07 7:42 
AnswerRe: Re-use code Pin
Kristian Sixhøj6-Nov-07 7:44
Kristian Sixhøj6-Nov-07 7:44 
GeneralRe: Re-use code Pin
simsen6-Nov-07 9:35
simsen6-Nov-07 9:35 
AnswerA few things Pin
Ennis Ray Lynch, Jr.6-Nov-07 8:14
Ennis Ray Lynch, Jr.6-Nov-07 8:14 
GeneralRe: A few things Pin
simsen6-Nov-07 9:38
simsen6-Nov-07 9:38 
GeneralRe: A few things Pin
Ennis Ray Lynch, Jr.6-Nov-07 9:42
Ennis Ray Lynch, Jr.6-Nov-07 9:42 
GeneralRe: A few things Pin
simsen6-Nov-07 10:00
simsen6-Nov-07 10:00 
GeneralRe: A few things Pin
Ennis Ray Lynch, Jr.6-Nov-07 10:54
Ennis Ray Lynch, Jr.6-Nov-07 10:54 
QuestionTreeView.SelectedNode.FullPath problem Pin
gerbenschmidt6-Nov-07 7:10
gerbenschmidt6-Nov-07 7:10 
AnswerRe: TreeView.SelectedNode.FullPath problem Pin
Alan N6-Nov-07 8:24
Alan N6-Nov-07 8:24 
GeneralRe: TreeView.SelectedNode.FullPath problem Pin
gerbenschmidt6-Nov-07 12:44
gerbenschmidt6-Nov-07 12:44 
QuestionQuestion about midi? Pin
Alphacore6-Nov-07 6:30
Alphacore6-Nov-07 6:30 
Questionspecify the number of users in XP Pro sp2 Pin
NvN>C6-Nov-07 6:08
NvN>C6-Nov-07 6:08 
AnswerRe: specify the number of users in XP Pro sp2 Pin
Guffa6-Nov-07 6:17
Guffa6-Nov-07 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.