473,717 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[QQ] Setting SendTimeout on TCPIP Sockets

Dear Group,

I am having a problem setting SocketOptionNam e.SendTimeout on a client
TCPIP application using the sockets in .NET. From the on-line help it
is possible to set a SocketOptionNam e.SendTimeout for sends on TCPIP

In all the tests that I have done with both Async and Sync sends the
send returns immediately with the number of bytes sent (< 100 in my

However the send may not have actually completed sending the data at
this time.

In the example below I connect to a server and then remove the
ethernet cable from the server and press the send button on my
application. I expect since the send has not delivered the packet to
the server that the send would time-out and an exception would occur.

However what actually happens is the send returns immediately
reporting that the data has been sent. I can see from a protocol
analyser that Windows tries to resend the data several times.

In my application I need to know that the data has not been sent as
after the timeout period as it is not valid any more. I do not want
windows to try to continue sending it after this timeout period.l

How can I detect that the data has not actually been sent within the
timeout period to the remote server?

How does Windows tell my TCPIP application that the data was not sent?
Is there an event that I need to look for?

Does Windows store the data in an internal buffer then forward the
messages from my application? Is it possible to inquire into this
buffer that the data has been delivered or timed-out to the remote
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Net;
using System.Net.Sock ets;

namespace simplesend
public class Form1 : System.Windows. Forms.Form
private Socket tcpsocket;
private System.Windows. Forms.Button Connect;
private System.Windows. Forms.Button Send;
private System.Windows. Forms.Label ConnectionStatu s;
private System.Windows. Forms.Label SendStatus;
private System.Componen tModel.Containe r components = null;

public Form1()
InitializeCompo nent();

protected override void Dispose( bool disposing )
if( disposing )
if (components != null)
components.Disp ose();
base.Dispose( disposing );

#region Windows Form Designer generated code

private void InitializeCompo nent()
this.Connect = new System.Windows. Forms.Button();
this.Send = new System.Windows. Forms.Button();
this.Connection Status = new System.Windows. Forms.Label();
this.SendStatus = new System.Windows. Forms.Label();
this.SuspendLay out();

this.Connect.Lo cation = new System.Drawing. Point(80, 16);
this.Connect.Na me = "Connect";
this.Connect.Si ze = new System.Drawing. Size(128, 48);
this.Connect.Ta bIndex = 2;
this.Connect.Te xt = "Connect";
this.Connect.Cl ick += new System.EventHan dler(this.Conne ct_Click);

this.Send.Locat ion = new System.Drawing. Point(72, 128);
this.Send.Name = "Send";
this.Send.Size = new System.Drawing. Size(136, 56);
this.Send.TabIn dex = 3;
this.Send.Text = "Send";
this.Send.Click += new System.EventHan dler(this.Send_ Click);

this.Connection Status.Location = new System.Drawing. Point(88, 72);
this.Connection Status.Name = "ConnectionStat us";
this.Connection Status.Size = new System.Drawing. Size(112, 24);
this.Connection Status.TabIndex = 4;
this.Connection Status.Text = "Not Connected";

this.SendStatus .Location = new System.Drawing. Point(88, 200);
this.SendStatus .Name = "SendStatus ";
this.SendStatus .Size = new System.Drawing. Size(120, 16);
this.SendStatus .TabIndex = 5;
this.SendStatus .Text = "Nothing Sent";

this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.SendSta tus);
this.Controls.A dd(this.Connect ionStatus);
this.Controls.A dd(this.Send);
this.Controls.A dd(this.Connect );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

static void Main()
Application.Run (new Form1());

private void Connect_Click(o bject sender, System.EventArg s e)
tcpsocket = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
tcpsocket.SetSo cketOption(Sock etOptionLevel.S ocket,
SocketOptionNam e.SendTimeout, 5000);
IPEndPoint remoteServerEnd Point = new IPEndPoint(
IPAddress.Parse ("") , 5000 );
tcpsocket.Block ing = true;
tcpsocket.Conne ct(remoteServer EndPoint);
catch (SocketExceptio n socketException )
socketException = socketException ;
if (tcpsocket.Conn ected) ConnectionStatu s.Text = "Connected" ;

private void Send_Click(obje ct sender, System.EventArg s e)
Byte[] buffer = new byte[5];
buffer[0] = System.Convert. ToByte('H');
buffer[1] = System.Convert. ToByte('e');
buffer[2] = System.Convert. ToByte('l');
buffer[3] = System.Convert. ToByte('l');
buffer[4] = System.Convert. ToByte('o');
int numBytes = 0;
numBytes = tcpsocket.Send (buffer, SocketFlags.Non e);
if (tcpsocket.Conn ected) SendStatus.Text = numBytes.ToStri ng();
catch (SocketExceptio n socketException )
socketException = socketException ;
Nov 16 '05 #1
0 2350

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

Similar topics

by: Bob Harrison | last post by:
I will be distributing an application that works with our security panel. The application can be loaded on several workstations in a network but only one workstation actually communicates via serial port or tcpip with the security panel. I modified the client chat sample that you have in your .net tcpip samples so that I can send info back and forth between the main (polling) workstation and any other workstations. The info is not keyed...
by: Milosz - [playseven.com] | last post by:
Dim EP As System.Net.IPEndPoint = New System.Net.IPEndPoint(mIP, mPort) Dim S As Socket = New Socket(EP.AddressFamily, SocketType.Dgram, ProtocolType.Udp) S.SetSocketOption(Sockets.SocketOptionLevel.Socket, Sockets.SocketOptionName.SendTimeout, Me.mTimeOUT) .......
by: vooose | last post by:
Consider a class MyTcpClient that : from TcpClient... MyTcpClient tcpClient = new MyTcpClient(); tcpClient.Client = tcpListener.AcceptSocket(); tcpClient.SendTimeout = 5000; //5 seconds //now pull the cable out the back of the computer the connection was just made to
by: Mike Sharp | last post by:
I'm fairly new to the C# scene, having been a VB6 programmer for what seems like a age (I used to push VB6 to its absolute limits when handling numerous connections from TCPIP sources). I'm looking for some fairly straight forward examples showing how I can create a non-blocking .NET C# application that can: - handle hundreds of connections per minute - read the incomming stream from multiple sources simultaneously and write it to a...
by: notregister | last post by:
Ji, i tried to use tcpclient to send a series of PCL command to a printer, but after going thru this, it print out a series of junk...the same series work well with another code i written for parallel...pls advise?? Public Function PrintChunkTCPIP(ByVal Chunk As String) As Long Dim x As Integer Dim client As New System.Net.Sockets.TcpClient("", 9100)
by: bizt | last post by:
Hi, I have been asked by my manager to look into the possiblily of setting up an online chat system for the external website. We run an Apache server with PHP (hence the reason Im posting here) so it would need to run on that. Basically, it will run on the website and its purpose will allow members of the public to access the chat room and discuss current topics with experts. Similar to a doctors interactive website where
by: DaTurk | last post by:
Hi, Lets see, for arguements sake lets just say that I have a server, which site waiting to receive connections, it then has an array of sockets that are connected to it. It's receiving all of this asynchronously. Now, this is my problem, I have a seperate application that connects to the server and can disconnect any of the sockets connected to it. But, lets just say I have one client connected, and then I attempt to disconnect them...
by: Hemant Shah | last post by:
Folks, I am having hard time figuring out the problem I have with setting up new DB2 instance. This is 22nd instance I am creating on the server and I have never encounterd this problem. My server and client (2 different systems) are running AIX 5.3 and DB2 8.2. On server I have created instance as follows: # ./db2icrt -a client -p 60085 -u db2fenc1 -s ese db2inst22
by: user1357 | last post by:
Hi All, Could you please explain the difference b/w the below codes? when qq is used with eval and without () the o/p is different. $hex1='\xd1';
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.