Click here to Skip to main content
15,888,816 members
Home / Discussions / C#
   

C#

 
Generalsocket timeout Pin
Rüpel20-Sep-02 3:27
Rüpel20-Sep-02 3:27 
GeneralRe: socket timeout Pin
Luis Alonso Ramos20-Sep-02 4:37
Luis Alonso Ramos20-Sep-02 4:37 
GeneralRe: socket timeout Pin
Rüpel22-Sep-02 22:23
Rüpel22-Sep-02 22:23 
Generalthis is not solved yet Pin
Rüpel23-Sep-02 4:00
Rüpel23-Sep-02 4:00 
GeneralRe: socket timeout Pin
Daniel Turini23-Sep-02 9:16
Daniel Turini23-Sep-02 9:16 
GeneralRe: socket timeout Pin
Rüpel23-Sep-02 10:09
Rüpel23-Sep-02 10:09 
Generalstill doesn't work Pin
Rüpel23-Sep-02 20:52
Rüpel23-Sep-02 20:52 
Generalfinally Pin
Rüpel23-Sep-02 21:53
Rüpel23-Sep-02 21:53 
now i did a 'hack' that works for me. Smile | :)

public class TimedUdpClient : UdpClient
{
	private int timeout = 1000; // 1 sec default
	private Thread timeoutWatchdog;

	/// <summary>
	/// Get/Set the receiving timeout in milliseconds (1000 = 1sec)
	/// </summary>
	public int Timeout
	{
		get { return timeout; }
		set { timeout = value; }
	}

	public new byte[] Receive(ref IPEndPoint remote)
	{
		timeoutWatchdog = new Thread(new ThreadStart(StartWatchdog));
		timeoutWatchdog.Start();
		try
		{
			byte[] ret = base.Receive(ref remote);
			return ret;
		}
		catch (SocketException)
		{
			return null;
		}
	}

	private void StartWatchdog()
	{
		Thread.Sleep(timeout);
		this.Send(new byte[] {0x00},1,"",8000);
	}
}


my little test-program from two or three postings above didn't receive the packets since they have to be sent on the same socket (at least i believe that). when this byte from my watchdog is sent, there's an exception ("connection closed by remote" or something like that) raised somewhere inside UdpClient.Receive(). it would be nicer, if it would just receive the byte and one could distinguish by the sender, if that packet was sent by the watchdog (thus, on the same socket) or comes from outside. UDP is a connectionless protocol, so i'm not sure, how such a connection-closed-excpetion may occur, but actually it does WTF | :WTF:

anyways. all i wanted, was stop Receive() from blocking and this way it works. Smile | :)

thx to everyone that helped. (also the ones that read, thought and had no idea)

:wq
GeneralEiffel .NET for Visual Studio .NET Plug-in Pin
Kevin McFarlane20-Sep-02 1:50
Kevin McFarlane20-Sep-02 1:50 
GeneralBackground and foreground color for disabled state Pin
valos20-Sep-02 1:18
valos20-Sep-02 1:18 
QuestionShut down one program from another? Pin
Matt Philmon19-Sep-02 18:11
Matt Philmon19-Sep-02 18:11 
AnswerRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 19:08
Stephane Rodriguez.19-Sep-02 19:08 
GeneralRe: Shut down one program from another? Pin
Matt Philmon19-Sep-02 20:50
Matt Philmon19-Sep-02 20:50 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.19-Sep-02 21:23
Stephane Rodriguez.19-Sep-02 21:23 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 4:47
Matt Philmon20-Sep-02 4:47 
GeneralRe: Shut down one program from another? Pin
leppie20-Sep-02 5:22
leppie20-Sep-02 5:22 
GeneralRe: Shut down one program from another? Pin
Matt Philmon20-Sep-02 21:33
Matt Philmon20-Sep-02 21:33 
GeneralRe: Shut down one program from another? Pin
Stephane Rodriguez.21-Sep-02 1:52
Stephane Rodriguez.21-Sep-02 1:52 
GeneralRe: Shut down one program from another? Pin
leppie21-Sep-02 2:01
leppie21-Sep-02 2:01 
GeneralRe: Shut down one program from another? Pin
Matt Philmon21-Sep-02 5:49
Matt Philmon21-Sep-02 5:49 
GeneralBeta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)19-Sep-02 12:30
Eric Gunnerson (msft)19-Sep-02 12:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
David Stone19-Sep-02 13:11
sitebuilderDavid Stone19-Sep-02 13:11 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Eric Gunnerson (msft)23-Sep-02 7:30
Eric Gunnerson (msft)23-Sep-02 7:30 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
Matt Philmon20-Sep-02 21:34
Matt Philmon20-Sep-02 21:34 
GeneralRe: Beta of .NET Framework Version 1.1 now available Pin
James T. Johnson21-Sep-02 2:07
James T. Johnson21-Sep-02 2:07 

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.