9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] serving html sites with announce, listen and accept (dial(2))
@ 2024-09-09  5:57 sahu
  2024-09-09  6:10 ` Alex Musolino
  0 siblings, 1 reply; 6+ messages in thread
From: sahu @ 2024-09-09  5:57 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 1855 bytes --]

hello everyone, 

I’ve made some small changes to the bekremvax-example in dial(2) in order to get a simple html response:

#include <u.h>
#include <libc.h>

int
bekremvax(void)
{
	int dfd, acfd, lcfd;
	char adir[40], ldir[40];
	int n;
	char *buf = „HTTP/1.1 200 OK\nContent-Type: text/html; charset=UTF-8\nContent-Length: 8\n\n<!DOCTYPE html><html><body>hello, world!</body></html>";
	acfd = announce("tcp!*!7", adir);
        if(acfd < 0)
        	return -1;
        for(;;){
        	/* listen for a call */
                lcfd = listen(adir, ldir);

                if(lcfd < 0)
                	return -1;
                /* fork a process to echo */
                switch(fork()){
                case -1:
                	perror("forking");
                        close(lcfd);
                        break;
                case 0:
                	/* accept the call and open the data file */
                        dfd = accept(lcfd, ldir);
                        if(dfd < 0)
                        	return -1;
			print(„incoming request“);
                        write(dfd, buf, sizeof(buf));
                        exits(nil);
                default:
                	close(lcfd);
                        break;
                }
	}
}
void
main()
{
	bekremvax();
	exits(nil);
}

in my browser I’m getting an empty page and with netcat the following output:
nc -v 10.211.55.3 7

Connection to 10.211.55.3 port 7 [tcp/discard] succeeded!

HTTP/1.1%      

there is also no print statement („incoming request“) when I’m trying to reach the service via browser. am I doing something wrong? 9front is running in a vm at the moment, but as far as I can tell there weren’t any issues regarding the network.

thank you very much in advance!

best regards, 
Sascha

[-- Attachment #2: Type: text/html, Size: 13533 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] serving html sites with announce, listen and accept (dial(2))
  2024-09-09  5:57 [9front] serving html sites with announce, listen and accept (dial(2)) sahu
@ 2024-09-09  6:10 ` Alex Musolino
  2024-09-09  7:28   ` sahu
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Musolino @ 2024-09-09  6:10 UTC (permalink / raw)
  To: 9front

You are declaring buf as a pointer-to-char so sizeof(buf) == 8.
Either use strlen instead of sizeof or declare buf as an array, i.e.
char buf[] = "...";

--
Cheers,
Alex Musolino


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] serving html sites with announce, listen and accept (dial(2))
  2024-09-09  6:10 ` Alex Musolino
@ 2024-09-09  7:28   ` sahu
  2024-09-09  8:12     ` sirjofri
  0 siblings, 1 reply; 6+ messages in thread
From: sahu @ 2024-09-09  7:28 UTC (permalink / raw)
  To: 9front

Thank you very much! In netcat I’m getting the full response now. 

Unfortunately, there is still no response in my browser. If anyone has any hints about this, I would be very happy to hear them. Until then, I will try to understand how a response is composed with the help of tcp80.c from Igor. 

Best regards, 
Sascha

> Am 09.09.2024 um 08:10 schrieb Alex Musolino <alex@musolino.id.au>:
> 
> You are declaring buf as a pointer-to-char so sizeof(buf) == 8.
> Either use strlen instead of sizeof or declare buf as an array, i.e.
> char buf[] = "...";
> 
> --
> Cheers,
> Alex Musolino
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] serving html sites with announce, listen and accept (dial(2))
  2024-09-09  7:28   ` sahu
@ 2024-09-09  8:12     ` sirjofri
  2024-09-09  9:09       ` sahu
  0 siblings, 1 reply; 6+ messages in thread
From: sirjofri @ 2024-09-09  8:12 UTC (permalink / raw)
  To: 9front

Hi,

09.09.2024 09:29:56 sahu@firstpost.pub:
> Thank you very much! In netcat I’m getting the full response now.
>
> Unfortunately, there is still no response in my browser. If anyone has any hints about this, I would be very happy to hear them. Until then, I will try to understand how a response is composed with the help of tcp80.c from Igor.

The Content-Length in your header is set to 8, which only covers the first tag, which is invisible. As far as I understand http, you have two options:

1) give it a proper value. This means that the client can reuse the connection by sending another request after the full response is received (HTTP/1.1).
2) remove the field completely and explicitly close the connection (e.g. by ending your program).

Good luck

sirjofri

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] serving html sites with announce, listen and accept (dial(2))
  2024-09-09  8:12     ` sirjofri
@ 2024-09-09  9:09       ` sahu
  2024-09-09 10:10         ` sirjofri
  0 siblings, 1 reply; 6+ messages in thread
From: sahu @ 2024-09-09  9:09 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

Thank you sirjofri! Unfortunately it still does not work, neither with an adjusted header, nor without the header.

Thanks again and best regards

> Am 09.09.2024 um 10:14 schrieb sirjofri <sirjofri+ml-9front@sirjofri.de>:
> 
> Hi,
> 
> 09.09.2024 09:29:56 sahu@firstpost.pub:
>> Thank you very much! In netcat I’m getting the full response now.
>> 
>> Unfortunately, there is still no response in my browser. If anyone has any hints about this, I would be very happy to hear them. Until then, I will try to understand how a response is composed with the help of tcp80.c from Igor.
> 
> The Content-Length in your header is set to 8, which only covers the first tag, which is invisible. As far as I understand http, you have two options:
> 
> 1) give it a proper value. This means that the client can reuse the connection by sending another request after the full response is received (HTTP/1.1).
> 2) remove the field completely and explicitly close the connection (e.g. by ending your program).
> 
> Good luck
> 
> sirjofri

[-- Attachment #2: Type: text/html, Size: 1929 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9front] serving html sites with announce, listen and accept (dial(2))
  2024-09-09  9:09       ` sahu
@ 2024-09-09 10:10         ` sirjofri
  0 siblings, 0 replies; 6+ messages in thread
From: sirjofri @ 2024-09-09 10:10 UTC (permalink / raw)
  To: 9front

09.09.2024 11:11:06 sahu@firstpost.pub:
> Thank you sirjofri! Unfortunately it still does not work, neither with an adjusted header, nor without the header.

Another point I recognized: line endings in HTTP are \r\n, not just \n. Try adding those.

sirjofri

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-09-09 10:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-09  5:57 [9front] serving html sites with announce, listen and accept (dial(2)) sahu
2024-09-09  6:10 ` Alex Musolino
2024-09-09  7:28   ` sahu
2024-09-09  8:12     ` sirjofri
2024-09-09  9:09       ` sahu
2024-09-09 10:10         ` sirjofri

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).