Question

I am using the HTTPListener class to implement a basic web server. My response uses a Content-Type of "multipart/x-mixed-replace" to return a stream of JPEG images. I am able to construct my response correctly, however my web client does not properly interpret the response due to the way in which the response is broken across IP packet boundaries.

Using a separate server implemented in python, I am able to generate a good, working case. The response to the client's HTTP GET request looks like this:

packet 1:
HTTP/1.1 200 OK

packet 2:
Server: (myServer)
Date: (the date)
Connection: close
(other header info)
Content-Type: multipart/x-mixed-replace; boundary=myboundary

packet 3:
--myboundary
Content-Length: 1042
Content-Type: image/jpeg

(jpeg data)

In the failed case, using the HTTPListener, everything gets sent in a single packet

packet 1:
HTTP/1.1 200 OK
Server: (myServer)
Date: (the date)
Connection: close
(other header info)
Content-Type: multipart/x-mixed-replace; boundary=myboundary

--myboundary
Content-Length: 1042
Content-Type: image/jpeg

(jpeg data)

So my question is, how do I manipulate the HTTPListenerResponse's OutputStream to force a packet boundary? I want to be able to specify some data, manually tell the OutputStream to push out a packet, then specify some more data and push out another packet. Does the HTTPListener offer this level of control, or do I need to instead use a TCPListener? I've not been able to find a solution; please help!

Was it helpful?

Solution

If your client doesn't work because of IP packet boundaries it is severely broken. Fix the client, don't add crutches for it in a place where there isn't a problem. HTTP is defined over TCP, and TCP is a byte-stream protocol. Period. Any correctly written TCP program, let alone an HTTP client, doesn't care where the packet boundaries are. If your client misbehaves in this way it will misbehave in other ways as well. Fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top