.NET Framework Bookmark and Share   
 index > .NET Framework Networking and Communication > Problem with .Net Stack When Using HTTP/XML and Port 80 & Port 8080
 

Problem with .Net Stack When Using HTTP/XML and Port 80 & Port 8080

Can someone provide any advice around the following problem. I hope it turns out to be a simple configuration setting, but we shall see.

I have some sample code that illustrates the problem (see later).

When I try to do the following:

1. Create a client/server connection (listening on port 8080)
2. Include an HTTP request/response between client and server
3. Keep the connection open, and drip feed tagged (kind-of-XML) snippets from the server (making sure they aren't too small)

What happens is that the drip fed data from the server is not seen by the client until a significant amount of data has been fed into the socket (>1KByte) (or the socket is closed).

If I change the server listening port to e.g. 9999 and do exactly the same thing again, then the behaviour is what I want - the data is seen by the client without having to wait.

If I feed text data, rather than XML-style tags it seems to work.

If I don't do the HTTP request/response then it seems to work.

If I do smaller XML snippets it seems to work.

We have spent a lot of time playing with socket options (all the ones we could find documented that seemed relevant), and couldn't make it behave as we require.

This behaviour was seen when trying to receive events from a device tunnelled using HTTP - and we found that the events didn't register until about 1.5 minutes after the original event was triggered. We could see the data coming across on the network when the events were happening, and after investigation we concluded that something is going on with the .Net Socket interface (it doesn't happen with unmanaged C socket code). Unfortunately we can't change the way the embedded device is behaving to compensate.

Note the behaviour was seen on both XP and Vista with .Net 3.5 framework installed (and developed using Visual Studio 2008).

If you run the client and server below with port 8080 you will see the problem. Then change the port in the shared code to 9999 you will see the behaviour we want (data received immediately by client).

Here is the client code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using SocketTestSharedData;

namespace sockettest
{
	class Program
	{
		const string address = "127.0.0.1";

		static void Main( string[] args )
		{
			Socket sock1 = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
			Console.WriteLine( "Client starting..." );
			byte[] response = new byte[ 1536 ];

			System.Threading.Thread.Sleep( 5000 );

			sock1.Connect( address, SharedData.port );

			sock1.Send( ASCIIEncoding.ASCII.GetBytes( SharedData.message1 ) );

			int length = sock1.Receive( response );

			Console.WriteLine( ASCIIEncoding.ASCII.GetString( response ).ToCharArray(), 0, length );

			length = sock1.Receive( response );
			Console.Write( ASCIIEncoding.ASCII.GetString( response ).ToCharArray(), 0, length );

			if ( length > SharedData.response2.Length )
			{
				Console.WriteLine( "\n\nWARNING: Not getting data through as expected..." );
			}
			else
			{
				length = sock1.Receive( response );
				Console.Write( ASCIIEncoding.ASCII.GetString( response ).ToCharArray(), 0, length );
			}

			Console.WriteLine( "\nClient closing" );
			sock1.Close();
			System.Threading.Thread.Sleep( 2000 );
		}
	}
}


Here is the server code (run in a separate process or thread from the client):

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Net;
using SocketTestSharedData;

namespace sockserver
{
	class Program
	{
		static void Main( string[] args )
		{
			//
			// Create listening socket
			//
			Socket sock = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
			IPEndPoint ep = new IPEndPoint(IPAddress.Any, SharedData.port);
			byte[] command = new byte[ 1536 ];
			Console.WriteLine( "Server starting..." );

			sock.Bind( ep );
			sock.Listen( 10 );

			Socket conn1 = sock.Accept();
			int length = conn1.Receive( command );
			Console.Write( ASCIIEncoding.ASCII.GetString( command ).ToCharArray(), 0, length );
			conn1.Send( ASCIIEncoding.ASCII.GetBytes( SharedData.response1 ) );

			System.Threading.Thread.Sleep( 2000 );

			Console.WriteLine( "Server sending..." );
			conn1.Send( ASCIIEncoding.ASCII.GetBytes( SharedData.response2 ), SharedData.response2.Length, 0 );

			System.Threading.Thread.Sleep( 2000 );

			Console.WriteLine( "Server sending..." );
			conn1.Send( ASCIIEncoding.ASCII.GetBytes( SharedData.response3 ), SharedData.response3.Length, 0 );

			System.Threading.Thread.Sleep( 5000 );

			Console.WriteLine( "Server closing" );
			conn1.Close();
			sock.Close();
			System.Threading.Thread.Sleep( 2000 );
		}
	}
}

Here is the shared code:

using System;
using System.Collections.Generic;
using System.Text;

namespace SocketTestSharedData
{
	class SharedData
	{
		public const string message1 = "GET /something.html HTTP/1.1\r\n\r\n";
		public const string response1 = "HTTP/1.1 200 OK\r\n\r\n";
		public const string response2 = "<reply><indent><indent2>Hello</indent2></indent><indent>World</indent><indent><indent2>!</indent2></indent></reply>";
		public const string response3 = "<reply><indent><indent2>Blah</indent2></indent><indent>Blah</indent></reply>";

		//public const int port = 9999;
		public const int port = 8080;
	}
}

Many thanks for getting this far!
hammy1234
Hi all (Feroze and Alan),

OK, we got to the bottom of it... nothing to do with .Net.

It was the web shield operation of our AVG - it snoops 80, and 8080 (and 3128).

Many thanks for your time and help, and hope this is useful for anyone else who has problems with data coming through on these ports.

The reason we were suspicious of .Net is that unmanaged sockets (C sockets) worked fine.

Best Regards,

Robert

  • Marked As Answer byhammy1234 Tuesday, September 15, 2009 2:28 PM
  •  
hammy1234
I cannot repro your problem. I used your code exactly as is, and ran the server on a separate thread. I am not seeing the hangs you talk about, other than those related to the Sleep() calls you have put in the code.

feroze
--
My blog
Feroze Daud
Hi Feroze,

Many thanks for taking the time to try it out.

Perhaps I should clarify that the test application doesn't hang in either instance. If you run with port 8080 and then 9999 the application will complete in both instances, but with 8080 you will see an additional message:

WARNING: Not getting data through as expected...
Which shows that the two packets have been concatenated together, and only delivered when the server shuts down the socket.

We have tried on about 8 different PCs, a mix of Vista and XP, and always with the same results. It may be the case that you genuinely are seeing no difference in the behaviour between 8080 and 9999 and that is very interesting, and at the same time very hard to explain!

Many thanks again in taking the time to run the test.

Robert

hammy1234

Ah! I see what your problem is.

See, TCP is a stream interface, it is not a message interface. In other words, if your server writes a 1K (1024 byte) packet, it does not mean that the client will read the exact same with one call to Socket.Receive(). You will have to continue reading until you get enough data that you expect.

Byte [] buffer = new byte[1024];
int read = socket.Receive(buffer, 0, buffer.Length);
MemoryStream ms = new MemoryStream();
while (read > 0)
{
    ms.Write(buffer, 0, read);
    read = socket.Receive(buffer, 0, buffer.Length);
}

//  if you have gotten all the data you need, then you can get the data that you have stored.

ms.Seek(0,  SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
Console.WriteLine("Received data: " + sr.ReadToEnd());




Also see the following: http://blogs.msdn.com/joncole/archive/2006/03/20/555721.aspxfor a very good example on how to do message framing with Tcp. In fact, you should be able to directly use the SendMessage() and ReadMessage() functions in your code, and it will solve your problem!

feroze
--
My blog
  • Proposed As Answer byFeroze Daud Sunday, September 13, 2009 10:02 PM
  • Edited byFeroze Daud Sunday, September 13, 2009 10:05 PMAdded links to an example for message framing with Tcp sockets.
  •  
Feroze Daud
Hi Feroze,

I appreciate the information you are giving. Unfortunately it doesn't explain why using port 9999 should behave differently from port 8080. I should also point out the following:

1. The sample I have given is a "minimal criminal" - a minimal set of code that illustrates an unexpected difference in behaviour between ports 8080 and 9999 - this is not the original code that first brought the problem to our attention which does things in a much more engineered way (including code that performs a similar task to what you suggest)

2. What you are illustrating is the transmission of a large amount of data being broken into smaller pieces by the underlying transport. However, my issue is small packets being accumulated over significant periods of time within the PCs TCP/IP stack into larger packets before the stack gives me the data. And here are the key points: ONLY for HTTP related ports, and ONLY within the receiving stack

(NB: disabling Nagle's algorithm makes no difference)

My concern is that we are showing up behaviour within the .Net framework that for our purposes is undesirable, even though this may be by design (e.g. for security considerations). My hope is that there may be a system setting somewhere that will allow us to change the behaviour of the stack for these very specific HTTP related ports.

Thanks again!

Robert

hammy1234

The fact that you are seeing a difference between port 8080 and 9999 might not have any relevance. Note, that I am not saying that TCP will always break up your packet, I am saying that you cannot guarantee that one Send will cause one Receive() to read all the data sent. Which does not mean that it never will - it means that sometimes it may, and sometimes it may not.

So, the fact that 8080 != 9999 in terms of message framing might just have to do with how the TCP stack is behaving at that time, and it is totally within the protocol definition to behave like that.

Now, if you are still not convinced, the only way to investigate this further, is to provide a system.net log (I gave a link above) and also a network sniff using wireshark (http://www.wireshark.org)

Also, are you writing the HTTP server yourself, or are you using another software, like IIS/Apache or a custom app using System.Net.HttpListener or HTTP.sys driver?


feroze
--
My blog
Feroze Daud
Hi Feroze,

The behaviour difference between 8080 and 9999 is _very_ significant and is _very_ specific (in the example, try other port numbers).

The example provided illustrates the problem succinctly. This has been distilled out of the behaviour shown in the wider system (the initial post describes relevant elements of that system including what is seen on the network and the type of server).

The issue is not the breaking up of packets (sends < receives), it is:

1. The accumulation of small packets into a larger packet within the stack (sends > receives)
2. The subsequent delay in presenting that data to the socket

I believe you are going in the correct direction with message framing. I have a very strong suspicion that this is related to some kind of framing logic that has been built into the network stack for the .Net framework - and is being applied based on the specific port being used and type of data being transmitted on the port (see initial post).

However, I want to find a way to turn this off... it is undesirable behaviour for the operation of our application.

I would go further and argue that what is being applied within the stack to port 8080 is actually _outside_ the protocol definition - a TCP socket should present data in a timely manner even with Nagle's algorithm enabled. Try increasing the time-out before closing the server socket to a minute (or 10 minutes!!) to see what I mean!

I am grateful for the time you are taking. Unfortunately we appear to be diverging away from understanding what has been illustrated in the example.

Thanks,

Robert
hammy1234
I'm willing to bet that there's a proxy/firewall/NAT in between your two devices. It just passes most traffic unaffected, but for web traffic it wants to cache it, or to make sure its not prohibited content. So for web traffic it waits for all the content to arrive.

As Feroze noted, get a sniffer and see how the packets arrive at your machine. Lets not speculate until we've seen that.
http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
Alan J. McFarlane
Further information from logging the client behaviour (System.Net.log).

3 examples:

1. HTTP Get operation with subsequent XML over port 8080
2. HTTP Get operation with subsequent XML over port 9999
3. Get operation with HTTB typed instead of HTTP over port 8080 (shows the issue is triggered by protocol used)

Only in first example is the delay and accumulation of multiple packets seen. I hope this makes it very clear...

Port 8080 (HTTP Get)

System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Socket()
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Connect(127.0.0.1)
System.Net.Sockets Verbose: 0 : [6380] DNS::GetHostAddresses(127.0.0.1)
System.Net.Sockets Verbose: 0 : [6380] Exiting DNS::GetHostAddresses() -> IPAddress[]#44624228
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Connect(IPAddress[]#44624228)
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Connect(1:8080#16785391)
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Send()
System.Net.Sockets Verbose: 0 : [6380] Data from Socket#64923656::Send
System.Net.Sockets Verbose: 0 : [6380] 00000000 : 47 45 54 20 2F 73 6F 6D-65 74 68 69 6E 67 2E 68 : GET /something.h
System.Net.Sockets Verbose: 0 : [6380] 00000010 : 74 6D 6C 20 48 54 54 50-2F 31 2E 31 0D 0A 0D 0A : tml HTTP/1.1....
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Send() -> 32#32
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [6380] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [6380] 00000000 : 48 54 54 50 2F 31 2E 31-20 32 30 30 20 4F 4B 0D : HTTP/1.1 200 OK.
System.Net.Sockets Verbose: 0 : [6380] 00000010 : 0A 0D 0A : ...
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Receive() -> 19#19
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [6380] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [6380] 00000000 : 3C 72 65 70 6C 79 3E 3C-69 6E 64 65 6E 74 3E 3C : <reply><indent><
System.Net.Sockets Verbose: 0 : [6380] 00000010 : 69 6E 64 65 6E 74 32 3E-48 65 6C 6C 6F 3C 2F 69 : indent2>Hello</i
System.Net.Sockets Verbose: 0 : [6380] 00000020 : 6E 64 65 6E 74 32 3E 3C-2F 69 6E 64 65 6E 74 3E : ndent2></indent>
System.Net.Sockets Verbose: 0 : [6380] 00000030 : 3C 69 6E 64 65 6E 74 3E-57 6F 72 6C 64 3C 2F 69 : <indent>World</i
System.Net.Sockets Verbose: 0 : [6380] 00000040 : 6E 64 65 6E 74 3E 3C 69-6E 64 65 6E 74 3E 3C 69 : ndent><indent><i
System.Net.Sockets Verbose: 0 : [6380] 00000050 : 6E 64 65 6E 74 32 3E 21-3C 2F 69 6E 64 65 6E 74 : ndent2>!</indent
System.Net.Sockets Verbose: 0 : [6380] 00000060 : 32 3E 3C 2F 69 6E 64 65-6E 74 3E 3C 2F 72 65 70 : 2></indent></rep
System.Net.Sockets Verbose: 0 : [6380] 00000070 : 6C 79 3E 3C 72 65 70 6C-79 3E 3C 69 6E 64 65 6E : ly><reply><inden
System.Net.Sockets Verbose: 0 : [6380] 00000080 : 74 3E 3C 69 6E 64 65 6E-74 32 3E 42 6C 61 68 3C : t><indent2>Blah<
System.Net.Sockets Verbose: 0 : [6380] 00000090 : 2F 69 6E 64 65 6E 74 32-3E 3C 2F 69 6E 64 65 6E : /indent2></inden
System.Net.Sockets Verbose: 0 : [6380] 000000A0 : 74 3E 3C 69 6E 64 65 6E-74 3E 42 6C 61 68 3C 2F : t><indent>Blah</
System.Net.Sockets Verbose: 0 : [6380] 000000B0 : 69 6E 64 65 6E 74 3E 3C-2F 72 65 70 6C 79 3E : indent></reply>
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Receive() -> 191#191
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Close()
System.Net.Sockets Verbose: 0 : [6380] Socket#64923656::Dispose()
System.Net.Sockets Verbose: 0 : [6380] Exiting Socket#64923656::Close()

Port 9999 (HTTP Get)

System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Socket()
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Connect(127.0.0.1)
System.Net.Sockets Verbose: 0 : [4872] DNS::GetHostAddresses(127.0.0.1)
System.Net.Sockets Verbose: 0 : [4872] Exiting DNS::GetHostAddresses() -> IPAddress[]#44624228
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Connect(IPAddress[]#44624228)
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Connect(1:9999#16787312)
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Send()
System.Net.Sockets Verbose: 0 : [4872] Data from Socket#64923656::Send
System.Net.Sockets Verbose: 0 : [4872] 00000000 : 47 45 54 20 2F 73 6F 6D-65 74 68 69 6E 67 2E 68 : GET /something.h
System.Net.Sockets Verbose: 0 : [4872] 00000010 : 74 6D 6C 20 48 54 54 50-2F 31 2E 31 0D 0A 0D 0A : tml HTTP/1.1....
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Send() -> 32#32
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [4872] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [4872] 00000000 : 48 54 54 50 2F 31 2E 31-20 32 30 30 20 4F 4B 0D : HTTP/1.1 200 OK.
System.Net.Sockets Verbose: 0 : [4872] 00000010 : 0A 0D 0A : ...
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Receive() -> 19#19
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [4872] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [4872] 00000000 : 3C 72 65 70 6C 79 3E 3C-69 6E 64 65 6E 74 3E 3C : <reply><indent><
System.Net.Sockets Verbose: 0 : [4872] 00000010 : 69 6E 64 65 6E 74 32 3E-48 65 6C 6C 6F 3C 2F 69 : indent2>Hello</i
System.Net.Sockets Verbose: 0 : [4872] 00000020 : 6E 64 65 6E 74 32 3E 3C-2F 69 6E 64 65 6E 74 3E : ndent2></indent>
System.Net.Sockets Verbose: 0 : [4872] 00000030 : 3C 69 6E 64 65 6E 74 3E-57 6F 72 6C 64 3C 2F 69 : <indent>World</i
System.Net.Sockets Verbose: 0 : [4872] 00000040 : 6E 64 65 6E 74 3E 3C 69-6E 64 65 6E 74 3E 3C 69 : ndent><indent><i
System.Net.Sockets Verbose: 0 : [4872] 00000050 : 6E 64 65 6E 74 32 3E 21-3C 2F 69 6E 64 65 6E 74 : ndent2>!</indent
System.Net.Sockets Verbose: 0 : [4872] 00000060 : 32 3E 3C 2F 69 6E 64 65-6E 74 3E 3C 2F 72 65 70 : 2></indent></rep
System.Net.Sockets Verbose: 0 : [4872] 00000070 : 6C 79 3E : ly>
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Receive() -> 115#115
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [4872] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [4872] 00000000 : 3C 72 65 70 6C 79 3E 3C-69 6E 64 65 6E 74 3E 3C : <reply><indent><
System.Net.Sockets Verbose: 0 : [4872] 00000010 : 69 6E 64 65 6E 74 32 3E-42 6C 61 68 3C 2F 69 6E : indent2>Blah</in
System.Net.Sockets Verbose: 0 : [4872] 00000020 : 64 65 6E 74 32 3E 3C 2F-69 6E 64 65 6E 74 3E 3C : dent2></indent><
System.Net.Sockets Verbose: 0 : [4872] 00000030 : 69 6E 64 65 6E 74 3E 42-6C 61 68 3C 2F 69 6E 64 : indent>Blah</ind
System.Net.Sockets Verbose: 0 : [4872] 00000040 : 65 6E 74 3E 3C 2F 72 65-70 6C 79 3E : ent></reply>
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Receive() -> 76#76
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Close()
System.Net.Sockets Verbose: 0 : [4872] Socket#64923656::Dispose()
System.Net.Sockets Verbose: 0 : [4872] Exiting Socket#64923656::Close()

Port 8080 (Using HTTB instead of HTTP)

System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Socket()
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Connect(127.0.0.1)
System.Net.Sockets Verbose: 0 : [4100] DNS::GetHostAddresses(127.0.0.1)
System.Net.Sockets Verbose: 0 : [4100] Exiting DNS::GetHostAddresses() -> IPAddress[]#44624228
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Connect(IPAddress[]#44624228)
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Connect(1:8080#16785391)
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Connect()
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Send()
System.Net.Sockets Verbose: 0 : [4100] Data from Socket#64923656::Send
System.Net.Sockets Verbose: 0 : [4100] 00000000 : 47 45 54 20 2F 73 6F 6D-65 74 68 69 6E 67 2E 68 : GET /something.h
System.Net.Sockets Verbose: 0 : [4100] 00000010 : 74 6D 6C 20 48 54 54 42-2F 31 2E 31 0D 0A 0D 0A : tml HTTB/1.1....
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Send() -> 32#32
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [4100] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [4100] 00000000 : 48 54 54 50 2F 31 2E 31-20 32 30 30 20 4F 4B 0D : HTTP/1.1 200 OK.
System.Net.Sockets Verbose: 0 : [4100] 00000010 : 0A 0D 0A : ...
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Receive() -> 19#19
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [4100] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [4100] 00000000 : 3C 72 65 70 6C 79 3E 3C-69 6E 64 65 6E 74 3E 3C : <reply><indent><
System.Net.Sockets Verbose: 0 : [4100] 00000010 : 69 6E 64 65 6E 74 32 3E-48 65 6C 6C 6F 3C 2F 69 : indent2>Hello</i
System.Net.Sockets Verbose: 0 : [4100] 00000020 : 6E 64 65 6E 74 32 3E 3C-2F 69 6E 64 65 6E 74 3E : ndent2></indent>
System.Net.Sockets Verbose: 0 : [4100] 00000030 : 3C 69 6E 64 65 6E 74 3E-57 6F 72 6C 64 3C 2F 69 : <indent>World</i
System.Net.Sockets Verbose: 0 : [4100] 00000040 : 6E 64 65 6E 74 3E 3C 69-6E 64 65 6E 74 3E 3C 69 : ndent><indent><i
System.Net.Sockets Verbose: 0 : [4100] 00000050 : 6E 64 65 6E 74 32 3E 21-3C 2F 69 6E 64 65 6E 74 : ndent2>!</indent
System.Net.Sockets Verbose: 0 : [4100] 00000060 : 32 3E 3C 2F 69 6E 64 65-6E 74 3E 3C 2F 72 65 70 : 2></indent></rep
System.Net.Sockets Verbose: 0 : [4100] 00000070 : 6C 79 3E : ly>
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Receive() -> 115#115
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Receive()
System.Net.Sockets Verbose: 0 : [4100] Data from Socket#64923656::Receive
System.Net.Sockets Verbose: 0 : [4100] 00000000 : 3C 72 65 70 6C 79 3E 3C-69 6E 64 65 6E 74 3E 3C : <reply><indent><
System.Net.Sockets Verbose: 0 : [4100] 00000010 : 69 6E 64 65 6E 74 32 3E-42 6C 61 68 3C 2F 69 6E : indent2>Blah</in
System.Net.Sockets Verbose: 0 : [4100] 00000020 : 64 65 6E 74 32 3E 3C 2F-69 6E 64 65 6E 74 3E 3C : dent2></indent><
System.Net.Sockets Verbose: 0 : [4100] 00000030 : 69 6E 64 65 6E 74 3E 42-6C 61 68 3C 2F 69 6E 64 : indent>Blah</ind
System.Net.Sockets Verbose: 0 : [4100] 00000040 : 65 6E 74 3E 3C 2F 72 65-70 6C 79 3E : ent></reply>
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Receive() -> 76#76
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Close()
System.Net.Sockets Verbose: 0 : [4100] Socket#64923656::Dispose()
System.Net.Sockets Verbose: 0 : [4100] Exiting Socket#64923656::Close()

hammy1234
Hi Alan,

Many thanks for coming in to the discussion. Forget about my real world situation for now, and concentrate on what is illustrated by the example code in my original post.

No speculation is required!

The example code client and server, when run as two separate processes on the same machine _will_ illustrate the problem. This was created to avoid any ambiguity that there may be a proxy/Firewall/NAT somewhere in the network, and allow anyone interested to replicate the issue as I see it.

It is there to try out, if you have the time:

1. If the client process receives and prints out the data as it is being sent by the server - that is behaving as I would like

2. If the client process only receives data after the server socket is closed, then the network stack is imposing undesirable behaviour (if only for the requirements imposed on my application)

I am looking for a means to modify the .Net socket behaviour to stop this behaviour (2. above) that I only see when using port 8080.

If you do not see the same behaviour, and port 8080 behaves as other ports, then that is interesting - something on your PC is different, and there should be a way for me to force the desired behaviour on the socket on my PC. I just need to figure out what that is.

It may be the case that it is not possible to turn this behaviour off - and this has been imposed by design for very good reasons!

I hope someone has an answer...

Best Regards,

Robert

hammy1234
Hi all (Feroze and Alan),

OK, we got to the bottom of it... nothing to do with .Net.

It was the web shield operation of our AVG - it snoops 80, and 8080 (and 3128).

Many thanks for your time and help, and hope this is useful for anyone else who has problems with data coming through on these ports.

The reason we were suspicious of .Net is that unmanaged sockets (C sockets) worked fine.

Best Regards,

Robert

  • Marked As Answer byhammy1234 Tuesday, September 15, 2009 2:28 PM
  •  
hammy1234

Aha! :-) I was just coming back to write: "What AntiVirus are you running on your machine?"


http://www.alanjmcf.me.uk/ Please follow-up in the newsgroup. If I help, mark the question answered
Alan J. McFarlane

You can use google to search for other answers

Custom Search

More Threads

• How do I expose WCF web services in IIS without using .svc files?
• Xml.load Document
• NetworkStream::BeginRead/BeginWrite problems
• How to access a secure (https) location through a Proxy Server that requires authentication
• Checking against an Active Directory store
• Programmatically login to HTTPS website with credentials C#
• Calling a stored SQL Proceedure from VB
• Download contents from a folder after connecting to remote server
• An existing connection was forcibly closed by the remote host
• [net2.0] FTP - GetFileSize