Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
GeneralExcel 2003 Custom Toolbar Flickers when any VBA Macro runs in the Excel Contest Pin
kellap25-Aug-04 1:54
kellap25-Aug-04 1:54 
GeneralOffice Excel 2003 with Information Bridge Framwork Pin
kellap25-Aug-04 1:50
kellap25-Aug-04 1:50 
GeneralRe: Office Excel 2003 with Information Bridge Framwork Pin
Heath Stewart25-Aug-04 9:33
protectorHeath Stewart25-Aug-04 9:33 
GeneralException in web services Pin
Diego F.25-Aug-04 0:18
Diego F.25-Aug-04 0:18 
GeneralRe: Exception in web services Pin
Salil Khedkar25-Aug-04 2:54
Salil Khedkar25-Aug-04 2:54 
GeneralRe: Exception in web services Pin
Salil Khedkar25-Aug-04 2:59
Salil Khedkar25-Aug-04 2:59 
GeneralRe: Exception in web services Pin
Nick Parker25-Aug-04 5:37
protectorNick Parker25-Aug-04 5:37 
GeneralCheck if TCP/IP partner disconnected... Pin
Norman-Timo24-Aug-04 23:18
Norman-Timo24-Aug-04 23:18 
Hello everybody!

I want to have a permanent data transfer to another machine via TCP/IP Socket Communication. I actually coded a solution which will work fine. But one thing does not work:

In my code the SocketServer does not recognize that the client has disconnected. How can I recognize this?

In the case that the client disconnected, my code is waiting for Data and there is logically no dataflow anymore.

Here´s the important extract from my code:



[STAThread]
public static void Main()
{
Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, 65000);

mySocket.Bind(myEndPoint);

try
{
mySocket.Listen(20);
Socket sa = mySocket.Accept();

byte[] buffer = new byte[5];
string tmpString = "";

NetworkStream myStream = new NetworkStream(sa, true);

while (sa != null)
{
if (myStream.DataAvailable)
{
int read = 0;
read = myStream.Read(buffer, 0, buffer.Length);
tmpString = Encoding.ASCII.GetString(buffer, 0, read);
Console.WriteLine(tmpString);
}
}
}
catch (SocketException sockErr)
{
Console.WriteLine("Socket Exception: ", sockErr.Message);
}
catch (Exception err)
{
Console.WriteLine("Exception: ", err.Message);
}


mySocket.Close();
}


Thanks for any help
Norman-Timo
GeneralRe: Check if TCP/IP partner disconnected... Pin
leppie25-Aug-04 1:45
leppie25-Aug-04 1:45 
GeneralRe: Check if TCP/IP partner disconnected... Pin
Norman-Timo25-Aug-04 3:16
Norman-Timo25-Aug-04 3:16 
GeneralRe: Check if TCP/IP partner disconnected... Pin
Sebastian Schneider25-Aug-04 4:54
Sebastian Schneider25-Aug-04 4:54 
GeneralRe: Check if TCP/IP partner disconnected... Pin
Norman-Timo25-Aug-04 20:54
Norman-Timo25-Aug-04 20:54 
QuestionCan anybody explain me how does casting work *internally*? Pin
Salil Khedkar24-Aug-04 20:40
Salil Khedkar24-Aug-04 20:40 
AnswerRe: Can anybody explain me how does casting work *internally*? Pin
leppie24-Aug-04 21:06
leppie24-Aug-04 21:06 
AnswerRe: Can anybody explain me how does casting work *internally*? Pin
Sebastian Schneider25-Aug-04 5:12
Sebastian Schneider25-Aug-04 5:12 
GeneralRe: Can anybody explain me how does casting work *internally*? Pin
Salil Khedkar25-Aug-04 20:45
Salil Khedkar25-Aug-04 20:45 
QuestionAre there dynamic array librarys available in C#? Pin
gotton24-Aug-04 20:10
gotton24-Aug-04 20:10 
AnswerRe: Are there dynamic array librarys available in C#? Pin
leppie24-Aug-04 21:04
leppie24-Aug-04 21:04 
AnswerRe: Are there dynamic array librarys available in C#? Pin
Norman-Timo25-Aug-04 3:21
Norman-Timo25-Aug-04 3:21 
GeneralDrawing Pin
Member 1697724-Aug-04 18:29
Member 1697724-Aug-04 18:29 
GeneralRe: Drawing Pin
sreejith ss nair24-Aug-04 18:56
sreejith ss nair24-Aug-04 18:56 
QuestionFirst time using Windows Forms -- Components not appearing? Pin
Waverian24-Aug-04 17:23
Waverian24-Aug-04 17:23 
AnswerRe: First time using Windows Forms -- Components not appearing? Pin
sreejith ss nair24-Aug-04 18:53
sreejith ss nair24-Aug-04 18:53 
QuestionSingleton ? Pin
Christian Graus24-Aug-04 16:06
protectorChristian Graus24-Aug-04 16:06 
AnswerRe: Singleton ? Pin
Heath Stewart24-Aug-04 16:11
protectorHeath Stewart24-Aug-04 16:11 

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.