1

I want to create a Http Server to send an MJPEG Stream. In the first place i therefore want to create a Simple Version that just sends some html/text. I've already Managed to set up a TCP-Server but I don't have any clue about how to "act" like an http Server.

What I did: Created an TCP-Server. When a client Connects a TCP-Socket is created. Then I implemented a ReadyRead SLOT which gots executed when the Browser sends the "GET" Request to the Server.

GET / HTTP/1.1
Host: 127.0.0.1:8889
User-Agent: Mozilla/5.0...

Then I run following Code

QByteArray header = "HTTP/ 1.1 200 OK\r\n";
m_Client->write(header);

QByteArray ContentType = "Content-Type: text/html\r\n";
m_Client->write(ContentType);

QByteArray Body = "Test";
m_Client->write(Body);

m_Client->close();

But what I see in the Browser is

HTTP/ 1.1 200 OK
Content-Type: text/html
Test

So what am I doing wrong? I thought about receiving the Client GET Request, sending the Header, Mimes and the Content in Return and Then Closing the Connection.... Is this Method wrong or Just the way I coded it?

hypnomaki
  • 593
  • 9
  • 22

1 Answers1

3

You have an extra space between the / and 1.1, and you are missing an empty line between the headers block and the response body.

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
  • Thanks that was fast and worked perfectly..... I'm almost feeling ashamed that it has been this easy ;) – hypnomaki Oct 11 '15 at 11:13
  • Next time check out your output a little more carefully against the specs, computers aren't really forgiving about errors in communication protocols. =) – Matteo Italia Oct 11 '15 at 11:41
  • sure ;) I also created another Question for The MJPEG Part. As For now I'm only able to send static images. Perhaps you can help me out a second time ;) http://stackoverflow.com/questions/33064955/how-to-create-a-http-mjpeg-streaming-server-with-qtcp-server-sockets – hypnomaki Oct 11 '15 at 12:32