Home » Windows OS

Winsock programming, delayed ack problem during retransmission on TCP\IP



This might not belong in the forum but since we use winsocket and visual studio there might be some tricks that we can use that I missed.

We had a case where a number of packges been dropped on the tcp\ip layer that forces retransmission in the tcp-layer (outside my programs control).

[TCP Previous segment lost]


and so on.

Then when the retransmission are starting to drop back in

[TCP Retransmission] (incoming)

[TCP Retransmission](incoming)

[TCP ACK] (outgoing)

This is all fine

All of a sudden the pattern changes to

[TCP Retransmission] (incoming)

[200 millisecond delay (delayed TCP ack)]

[TCP ACK] (outgoing)

[TCP Retransmission] (incoming)

[200 millisecond delay (delayed TCP ack)]

[TCP ACK] (outgoing)

[TCP Retransmission] (incoming)

[200 millisecond delay (delayed TCP ack)]

[TCP ACK] (outgoing)

Until at one point it starts sending us tons of data.

Now two questions: (one that doesn't fit into the programming space but rather windows server and networking).

1. Can I somehow force the ack to be sent faster then 200 millisecond if there only 1 segment sent? Not changes the whole computer just my program. (note, I shouldn't send data to the other party)

2. Why is winsocket not responding to each retransmission with an ack \ why is only 1 retransmission sent so that no ack is generated?


This is running x64 bit windows 2008 sp1

Compiled with Microsoft Visual studio 2008 version 9.0.307291 SP


3 Answers Found


Answer 1


Welcome to MSDN forums!

Are you using C++ to implement your application? If you get some problem with VC++ language, native windows API, please post some code here, we are glad to help you.

If you want to discuss the networking programming, we recommend you post the question to one of the following forums: http://social.msdn.microsoft.com/Forums/en-US/category/windevnetworking. If you are working on WCF or .Net Framework Networking, you may visit http://social.msdn.microsoft.com/Forums/en/wcf/threads/ or http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/threads. There are more experts who are familiar with networking issue.  

Once you know which forum is suitable for your question, we can help moving this thread to the particular forum.

Thank you for your understanding.

Yi Feng Li
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.


Answer 2

Thank you for you answer,

I think this question belongs to the Winsock Kernel (WSK) forum since I'm using C++ and not any of the .net platforms.


Answer 3

Hi Lars

Thank you for your confirmation. I’m moving this thread to Winsock Kernel Forum for better support.

Yi Feng Li
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.



I am developing a server side application using winsock, 

and everything works fine except that when i am listeng for connections from the client, the connection is dropped  (after the IP  of the origin of the connection is displayed)

 (i tested it out using telnet) 

in the method below i am listing for connections , inserting a connection into a wrapper object and putting that object into a vector.  


 int CServer_Socket::ListenforConnections() { 
	SOCKET client;
	sockaddr_in from;
	int fromlen=sizeof(from);

		char temp[512];
		cout << "waiting for connections......" << endl;
	client = accept(Socket,(struct sockaddr*)&from,&fromlen);
cout << "Connection from " << inet_ntoa(from.sin_addr) <<"\r\n";
		CClientWrapper ClientW (client,from);
class CClientWrapper

	SOCKET Client_Socket;


	CClientWrapper(SOCKET socket, sockaddr_in from) { 
		char temp[512];
		Client_Socket = socket;
    sprintf(temp,"KURT SAYS: Your IP is %s\r\n",inet_ntoa(from.sin_addr));


	~CClientWrapper() {

	SOCKET GetSocket() { return Client_Socket; }


why is this happening ?? 

and how do i fix it.

Thanks :) 



I am new to windows socket programming and also this forum. I got an "echo server" code from your site and changed it in order for it to receive a file and save it (in a while until all the data is read, all of the recv is from the same accepted socket).

while(file_size > 0){
    retval = recv(msgsock, Buffer, sizeof(Buffer), 0);
        myFile.write (Buffer, retval);
    file_size -= retval;

Until here everything was fine. Then for sending part, the original program just echos the Buffer which it has received. But when I change it to send Http header instead the program doesn't save the file.

//retval = send(msgsock, Buffer, sizeof(Buffer), 0);
retval = send(msgsock, http_msg, sizeof(http_msg), 0);

I don't know. maybe it is because I am using the same socket which receives the data to also send data. But why it works when I only echo the same data and not http header. Could some one please help me?

Thanks a lot.




 I have a problem in Windows 7 with 200ms ACK delays in TCP stream, when using clone-block-reinject mechanism at WFP Stream layer. This causes unacceptable slowdown.


 It can be observed also with the stmedit sample from the WDK, but I have created a simple minimal example code to demonstrate the problem. My minimal Stream Classify callout looks like this:


void StreamClassify(
IN const FWPS_INCOMING_VALUES0* inFixedValues,
IN OUT void* layerData,
IN const FWPS_FILTER0* filter,
IN UINT64 flowContext,
FWPS_STREAM_DATA0 *pStreamData = pIoPacket->streamData;

pIoPacket->streamAction = FWPS_STREAM_ACTION_NONE;
classifyOut->actionType = FWP_ACTION_PERMIT;
if (!(pStreamData->flags & FWPS_STREAM_FLAG_RECEIVE))
NTSTATUS NtStatus = FwpsCloneStreamData0(pStreamData, NULL, NULL, 0, &pClonedNbl);
if (!NT_SUCCESS(NtStatus))
KdPrint(("FwpsCloneStreamData0 error 0x%x\n", NtStatus));

NtStatus = FwpsStreamInjectAsync0(g_hInjection, NULL, 0, inMetaValues->flowHandle, g_nCalloutId, FWPS_LAYER_STREAM_V4,
pStreamData->flags, pClonedNbl, pStreamData->dataLength, ReinjectCompletion, NULL);
if (NT_SUCCESS(NtStatus))
classifyOut->actionType = FWP_ACTION_BLOCK;
else {
KdPrint(("FwpsStreamInjectAsync0 error 0x%x\n", NtStatus));
FwpsDiscardClonedStreamData0(pClonedNbl, 0, FALSE);

The callout performs clone-block-reinject for all incoming data, without modifying anything.


When I try to download a small file through HTTP, the ethernet dump (captured on the server) looks like this:


 1 0.000000 TCP 49190 > 80 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=8 SACK_PERM=1
2 0.000045 TCP 80 > 49190 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1460 WS=0 SACK_PERM=1
3 0.000230 TCP 49190 > 80 [ACK] Seq=1 Ack=1 Win=65536 Len=0
4 0.000794 HTTP GET /small/xaaaaaaaa HTTP/1.1
5 0.000813 TCP 80 > 49190 [ACK] Seq=1 Ack=85 Win=65451 Len=0
6 0.001286 TCP [TCP segment of a reassembled PDU]
7 0.001306 TCP [TCP segment of a reassembled PDU]
8 0.205701 TCP 49190 > 80 [ACK] Seq=85 Ack=2921 Win=65536 Len=0
9 0.205720 TCP [TCP segment of a reassembled PDU]
10 0.205742 TCP [TCP segment of a reassembled PDU]
11 0.205757 TCP [TCP segment of a reassembled PDU]
12 0.408418 TCP 49190 > 80 [ACK] Seq=85 Ack=7301 Win=65536 Len=0
13 0.408443 TCP [TCP segment of a reassembled PDU]
14 0.408465 TCP [TCP segment of a reassembled PDU]
15 0.408480 TCP [TCP segment of a reassembled PDU]
16 0.408494 TCP [TCP segment of a reassembled PDU]
17 0.626833 TCP 49190 > 80 [ACK] Seq=85 Ack=12289 Win=65536 Len=0
18 0.626868 HTTP HTTP/1.1 200 OK (application/octet-stream)
19 0.627109 TCP 49190 > 80 [ACK] Seq=85 Ack=13111 Win=64768 Len=0
20 0.628258 TCP 49190 > 80 [FIN, ACK] Seq=85 Ack=13111 Win=64768 Len=0
21 0.628264 TCP 80 > 49190 [ACK] Seq=13111 Ack=86 Win=65451 Len=0

The ACK delay can be seen on packets 8,12,17. When I stop the clone-drop-reinject driver, or when I change it to just permit all data, the delays are gone. Btw the delays are not always present, just sometimes. Until now I was not able to find any pattern defining when exactly it happens, and when not. But it is very easy to reproduce here (on a clean Win7 system, without any additional SW, with a Realtek RTL8168D NIC).


Is this known behaviour? Can I do something to prevent the ACK delays?


Thanks in advance for Your help,




I am writing a application/Win service which accesses the database and pushes the data to the clients on TCPIP port. The clients too request data many times but the ratio of the Server pushing the data is more than the Client requesting data.

I am planning to use TCPIP Listeners on the Client (3001) and the server(3000) and am not maintaining Client Server sessions. Every time the client wants some info, it will send a message to the server on 3000 on a asynchronous thread and the server replies back to all the clients with the same data on port 3001 on all the client listeners.

I dont think web service is ideal for this task. Am wondering if using WCF and TCPIP will be a better option.

Please can anyone help me out ?





PROBLEMCleint-server programming with Winsock 2.0, on computers connected on one 1000BaseT switch, Server side on Win 7 insanely slow, Server side on XP just fine!

Boiled-down version of client and server sides as below

1)server side: sock, bind, listen, accept, loop[send(64-byte hdr),recv(64-byte header), recv(bytes indicated in header)]

2)client side: sock, connect, loop[recv(64-byte header),send(64-byte header + several-K-byte body]

client puts body length in header before sending it to server side.

OK server side on XP, Client on XP and Window7 (32 home premium, 64 professional)

SLOW server on Win7, client on XP or Win7 - 2+ seconds for one round with Win7 Professional 64-bit, 6+ seconds for one round with Win7 Home Premium.

OK client and server sides on same PC, XP and Win7.

Seems Windows 7 has restrictions on socket from accept(), connections originated from aother computer, but has no restrictions on socket originated on the local computer to have connected to another computer.

This is true? If so, how do I take out this restriction, or is it ever possible to take it out this restriction - I have to use Win7 to develop server side programs before deployment after my company replaces all my xp computers with win7 ones. If not true, where do I configure winsock or anything to make the server side work on win7 without this outrageous delay?

Thanks a lot in advance for any help!



VB 2005 conversion from VB6

I basicly have 2 questions.

I am pulsing a relay up to 99 times per incident.  I need to delay between sending the pulse signals.  The delay time cannot change when I change between CPU speeds.  I am assuming the sleep() function will work fior this.  (This is a count of the number of game tokens to despense).

The second question is.. after I have pulsed the relay x number of times, I pulse another relay to send this number to a token machine to actually despense the tokens.  While the tokens are despensing (about 1.5 minutes do despense 99 tokens) I want to release the computer CPU so that the cashier can continue to sell items.  What command will allow me tho do this?

Thanks in advance




I'm using visual c++ 2010 express, and I'm experiencing a weird behavior.
Every time I try to run a program (even a simple 'hello world' one), the program is delayed a few seconds before it prints something. Same thing occurs with input: I need to wait a few seconds before i can enter input to the program.
No other programs that may cause this behavior run on the background, and this bug occurs everytime (restarting visual or the computer doesn't help).

After the initial delay, the program continues to run normally.

I will appreciate if someone can help me to solve this weird problem.



Hi everybody,

I am just learning about winsock and how to send and recieve data, so i decided my first step would be to make a console application instant messanger type program. I made a server version and a client version, so I sent one to my friend and if the server boots up first, the client will send the data to the server. However, when we tried this using the IP addresses we got off of whatsmyip.org , the client program failed on the connect(...) function, so SOCKET_ERROR came up and it closed the program. I tried it using Hamachi, and used the ip address that it gave us, and that works! we are able to communicate only when both logged into hamachi.

My question is: Why is this happening? and how do I get it to work with just the IP address of my computer and NOT with hamachi as a requirement?

I once had an old game that allowed for tcp/ip play, but in order for that to work it required hamachi also. I do not want my program to need this crutch. Thank you!



Hello everyone.

I try to create a server-side socket program that takes a single connection from one port and denying every connection while the old one is active, and when the client-side disconnect, the server then listen to another connection at the same port. So far, my code looks like this:

unsigned __stdcall listeningThread(void *arg)
	log(LOG_FILE_NAME,"CFTABridge created thread.");
	CFTABridge * pCFTABridge = (CFTABridge *) arg; //CFTABridge is the class name.  	while (1){

	log(LOG_FILE_NAME,"CFTABridge init socket");

	char buf[512] = "";
	int byte_count;
	while (globalsocket){

		byte_count = recv(globalsocket, buf, sizeof buf, 0);
		if (byte_count == 0) break;
		log(LOG_FILE_NAME,"CFTABridge connected.");

	log(LOG_FILE_NAME,"CFTABridge socket disconnected. Re-listening...");
return TRUE;

That's the threaded listening function, and there's another function created for listening:

SOCKET CFTABridge::ListenOnPort(int PortNo)

	addr.sin_family = AF_INET;
	addr.sin_port = htons(PortNo);
	addr.sin_addr.s_addr = inet_addr("");
	globalsocket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (globalsocket == INVALID_SOCKET)
		log(LOG_FILE_NAME,"CFTABridge create socket failed");
    return FALSE; //Don't continue if we couldn't create a socket!!
	log(LOG_FILE_NAME,"CFTABridge Socket created");

	if (bind(globalsocket, (LPSOCKADDR)&addr, sizeof(addr)) == SOCKET_ERROR)
		log(LOG_FILE_NAME,"CFTABridge bind socket failed");
    //We couldn't bind (this will happen when trying to bind to the same //socket more than once)return FALSE;
	log(LOG_FILE_NAME,"CFTABridge Socket binded.");

	listen(globalsocket, 0);
	log(LOG_FILE_NAME,"CFTABridge listening started.");

	log(LOG_FILE_NAME,"CFTABridge waiting for connection...");
	SOCKET AcceptSocket;
  AcceptSocket = INVALID_SOCKET;
		while (AcceptSocket == INVALID_SOCKET){
				AcceptSocket = accept(globalsocket, NULL, NULL);
	log(LOG_FILE_NAME,"CFTABridge socket Accepted.");
  globalsocket = AcceptSocket;
	return globalsocket;

and I created SOCKET globalsocket; as a global variable.


The problem is, when I run this, the program can connects fine at first connection. But when I disconnect and try to reconnect, it created another socket and bind, and failed.

When I netstat -a, I found that the port is still listening, even after my connection connected, and after the connection disconnected. The listening on port is still there and it never go away EVEN if the socket it's listening for is already closesocket'd.

another problem is I can still connect the second client while the first client still connects. it connects fine, but when I try to send something to the server's recv() function, it doesn't get through. Like it's connecting to the void. And when I try to connect the third one, now it returns socket error.

please tell me what I overlook or need fixing! I really need help, ASAP!



I'm having a slight problem with some of my winsock (client) code. The code itself is flawless but when the server sends me a packet which ends with a double carriage return \ line feed winsock promptly tells me the server has closed the connection.

I've written several versions of the code in both C++ & C# to no avail - however - If i write the code in PHP and run it off a Unix server the code will execute and the socket isn't closed when i receive a packet ending with a double CR \ LF.

Is there anyway to negate this issue or will i have to stick to PHP / *nix based systems.

Many thanks,
- Nobody


Hello everyone,

I wrote a small tool in C# which does nothing more than to Unpack a couple of files from A to B.

My Problem with the PCA is that whenever I close the Program on a Windows 7 machine (and my guess is on Vista too) that the a dialog pops up which is asking the user if the program was installed correctly. I can combine the pieces somehow and imagine why windows does it, but I would rather not have the users to be confused. What steps are necessary to stop the PCA asking the questions since it's not really an Installer?


Any help would be appreciated.




I am using Microsoft Project 2000.

I am a contractor and use MP 2000 to schedule projects. Each task is uniquely assigned to a responsible party (Subcontractor). If the responsible party delays a task, and it is a critical path task, then they are subject to liquidated damages. However, I need to easily identify which task(s) have been delayed, due to starting late or taking longer than the allowed duration, to fairly assign the damages. 'Start Variance', 'Duration Variance', and 'Finish Variance' are not good indicators because they do not account for delays caused by predecessors.

How can I identify which tasks have delayed a project and to what extent they delayed the project?


My C# program runs on Window's XP. It communicates with another Linux machine SW over the UDP/IP network. The two programs periodically exchange messages.

The message exchanges are fine, except for every once a while(maybe every minute, or shorter, or longer), the message-transfer got delayed for about 1 to 4 seconds. I don't know if it's my program got delayed on running(by some Window's programs), or delayed during network transferring? How can I debug this situation? Any suggestions?

Thanks a lot!


We have got several crash from customer (not reproduced ourself). I found some similar crash report on Internet, anybody knows about it? and is there any hotfix on it?

Windows 7 Kernel Version 7600 MP (8 procs) Free x64
Product: Server, suite: Enterprise TerminalServer
Built by: 7600.16539.amd64fre.win7_gdr.100226-1909

tcpip.sys time stamp:
Mon Jul 13 16:25:34 2009

fffff880`020cb668 fffff800`016c6b69 : 00000000`0000000a 00000000`0000001c 00000000`00000002 00000000`00000001 : nt!KeBugCheckEx
fffff880`020cb670 fffff800`016c57e0 : 00000003`00000010 00000000`00000001 fffff880`00000000 fffffa80`93928910 : nt!KiBugCheckDispatch+0x69
fffff880`020cb7b0 fffff880`01878c1a : 00000000`00000001 fffffa80`93928850 000000a0`cbe54985 00002c80`00000558 : nt!KiPageFault+0x260
fffff880`020cb940 fffff880`01877429 : ffff0000`039ac9b6 ffff0000`039ac9a6 fffffa80`96f34d30 00000000`00000001 : tcpip!TcpBeginTcbSend+0x32a
fffff880`020cbbc0 fffff880`018732b6 : 00000000`00000000 00000000`00000001 fffff880`01967128 00000000`00000000 : tcpip!TcpTcbSend+0x1d9
fffff880`020cbe40 fffff880`0187acac : fffffa80`93241000 00000000`00000000 00000000`00000000 fffff880`0185e300 : tcpip!TcpFlushDelay+0x316
fffff880`020cbf20 fffff880`0185d3c7 : fffffa80`91976bdc fffffa80`91955000 fffffa80`91726bdc 00000000`00000000 : tcpip!TcpPreValidatedReceive+0x20c
fffff880`020cbfd0 fffff880`0185d499 : fffff880`020cc150 fffff880`0196d9a0 fffff880`020cc160 fffff880`020cc0b0 : tcpip!IppDeliverListToProtocol+0x97
fffff880`020cc090 fffff880`0185d990 : fffffa80`9197a000 fffffa80`917fde00 fffffa80`9172a350 fffff880`020cc150 : tcpip!IppProcessDeliverList+0x59
fffff880`020cc100 fffff880`0185c821 : fffff880`020cc740 fffffa80`9197a000 fffff880`0196d9a0 00000000`93404001 : tcpip!IppReceiveHeaderBatch+0x231
fffff880`020cc1e0 fffff880`0185b272 : fffffa80`933fe110 00000000`00000000 fffffa80`93404001 fffff800`00000001 : tcpip!IpFlcReceivePackets+0x651
fffff880`020cc3e0 fffff880`018746ba : fffffa80`93404010 fffff880`020cc510 fffffa80`93404010 00000000`00000000 : tcpip!FlpReceiveNonPreValidatedNetBufferListChain+0x2b2
fffff880`020cc4c0 fffff800`016d6d4a : fffffa80`933a0c10 fffff880`020c7000 00000000`00004800 00000000`00000000 : tcpip!FlReceiveNetBufferListChainCalloutRoutine+0xda
fffff880`020cc510 fffff880`018740e2 : fffff880`018745e0 fffff880`020cc620 fffff800`018cdf02 fffff800`016af164 : nt!KeExpandKernelStackAndCalloutEx+0xda
fffff880`020cc5f0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : tcpip!FlReceiveNetBufferListChain+0xb2


Good evening,


I have a question about system service changes in Windows Vista Home Premium. I changed in my antivirus application a setting where I pointed to antivirus system, that it will notify me of any system service change that Windows will provide. Well, next I turned on my computer and there were system changes like:

"svchost.exe is attempting to delete Tcip"

"svchost.exe is attempting to delete netbt"

"wmiadap.exe is attempting to delete wmiprpl" (here I'm not sure, if this are the exact names of the files)


Is this a normal activity for a healthy Windows system or do I have there anybody running and changing my settings in my computer???


Thank you


well i want to show the time in an up to date type mode like a digiatal clock but seems unable to print it onto a label fast enough (and yes it is messy as it is my first program i am making.) oh and if this is in the wrong forum just tell me politely and dont ram unsightful comments down my throat please. any tips? The code is as follows  (using C#) .....

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Threading;

namespace Date.time


 //main formpublicpartialclass Form1 : Form


 public Form1()




 // time buttonprivatevoid timebtn_Click(object sender, EventArgs e)


 // loop ammount of timesfor (int count = 0; count <= 4; count++)

 { // find time

 DateTime thismoment = DateTime.Now;


  TimeLab.Text = thismoment.ToString("T");

 // sleep in milliseconds




 // date buttonprivatevoid DateBtn_Click(object sender, EventArgs e)

 { // find date

 DateTime thismoment = DateTime.Now;

 // display on label Datelab

 DateLab.Text = thismoment.Date.ToString("d");






I am trying to make simple TCPIP connection with 5 clients and one server. I want to have the clients connect to server using unique client ports. Based on the client port obtained on the server side, I need to identify the client as client 1 or client 2 etc. How can we assign client ports in winsock. Please let me know.



Hi all,

I am sumit. I want to send text data to multiple printers through ethernet (Winstock/TCPIP) in VB.NET. I am using visual studio 2008.

Please tell me what are the ways I can do this.


Sumit Sinha




I have a Approval work flow..What i am doing is,if the approver doesn't review with in a certain time-period the task will be send to another person in the company....

I did this by using Sharepoint List ..and i am using Listen Activity ...

Inside the Listen Activity i am using HandleExternalEventActivity and Delayas Parellel Activity...

But it does'nt work...I dont know how to extend it...

I refers many article...most of them said there is an issue in delay activity...i got conduced ..is that problem fixed or not ?

pls guide me...





I have a simple question. We had a application before working perfectly. we moved the application and the WCF into new server. unfortunately we are experiencing some delays/timeout in retreiving data . what do you think it cause?


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure