HttpListener Problems

395 views
Skip to first unread message

pat...@gmail.com

unread,
Feb 25, 2008, 2:38:35 PM2/25/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I have an HttpListener that I use to continually listen for http
requests. All it is to do is to receive the request, process the data
sent with the request, send back OK, and then listen for the next
request. The code for the callback method that I use can be found
here:

http://rafb.net/p/pElZNf62.html

For some reason, however, I am getting HttpListenerExceptions. I get
an "Incorrect Function" when using the output stream's ReadToEnd
method and "Parameter is Incorrect" when using the output stream's
Flush method. The code seems to work some times and not others.

Also, sometimes it seems a random "start of heading" character (ASCII
001) inserted into the data that I'm reading, which screws up my data.
What might cause that?

Can anybody see what I am doing wrong?

Thank you.

Andrew Badera

unread,
Feb 26, 2008, 5:54:16 AM2/26/08
to DotNetDe...@googlegroups.com
We need more code to be able to help you here. Especially the stream-reading stuff, and maybe some captured tcp streams to see what the request actually looks like.
--
--Andy Badera
http://andrew.badera.us/
and...@badera.us
(518) 641-1280
Google me: http://www.google.com/search?q=andrew+badera

Michael O

unread,
Feb 26, 2008, 11:57:14 AM2/26/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Is the defect reproducible? Do you have unit tests?

If yes on both, seeing your code (incl. the unit tests) is probably
required to help out. If it is a lot, use something like
pastebin.com

If no on either, that would be your first steps toward a solution to
this defect.

Michael O
http://blog.crisatunity.com

pat...@gmail.com

unread,
Feb 26, 2008, 4:51:12 PM2/26/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I'm happy to provide any code necessary, but in my original post I
included the entire callback method. I'm not sure what else would be
relevant. I show how I use the stream in the posted code in this line:

ProcessReceived(ipAddress, reader.ReadToEnd());

The only other code that I could see being relevant would be how I
declare the listener:

m_HttpListener = new HttpListener();
m_HttpListener.AuthenticationSchemes =
AuthenticationSchemes.Anonymous;
m_HttpListener.Prefixes.Add(String.Format("http://{0}:{1}/",
Utility.GetLocalIP(), GetFailoverPort()));
m_HttpListener.Start();

m_HttpListenerCallback = new AsyncCallback(ListenerCallback);
m_HttpListener.BeginGetContext(m_HttpListenerCallback,
m_HttpListener);

and the embedded code that sends the request (written in C++):

http://pastebin.com/m52b84df8

Here is the original code that I posted as well (since I believe it
has been taken down from the other paste site):

http://pastebin.com/m29683096

and here is what is received (retrieved via SmartSniff):

POST / HTTP/1.1
Host: 10.0.100.74:21559
Content-Length: 213
Expect: 100-continue

<Channel>
<Number>3</Number>
<Voltage>22.6738</Voltage>
<Current>0.456184</Current>
<FailoverState>1</FailoverState>
<VoltageState>audio</VoltageState>
<CurrentState>audio</CurrentState>
</Channel>

It only seems to happen every now and then, both the "Incorrect
Function" "Parameter is Incorrect" and the random ASCII 001 insertion
problem. Do the HTTP requests appear to be properly formed? Is there
some other code I should be providing? I really think I've covered all
sections that deal with the HTTP communications.

Thank you for your responses and your help.

pat...@gmail.com

unread,
Feb 27, 2008, 1:20:04 PM2/27/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
And here is an example of corrupted data:

<Channel>
<Number>1</Number>
<Voltage>24.5631</Voltage>
<Current>0.00 3ð </Current>
<FailoverState>1</FailoverState>
<VoltageState>audio</VoltageState>
<CurrentState>idle</CurrentState>
</Channel>

Notice that symbol in the Current node. So far it has only occurred in
that spot, though the characters that get inserted seem to be
different.

Reply all
Reply to author
Forward
0 new messages