9front - general discussion about 9front
 help / color / mirror / Atom feed
From: "sahu@firstpost.pub" <sahu@firstpost.pub>
To: 9front@9front.org
Subject: [9front] serving html sites with announce, listen and accept (dial(2))
Date: Mon, 9 Sep 2024 07:57:16 +0200	[thread overview]
Message-ID: <8DE37884-0209-400A-B603-00557873998C@firstpost.pub> (raw)

[-- 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 --]

             reply	other threads:[~2024-09-09  5:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-09  5:57 sahu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8DE37884-0209-400A-B603-00557873998C@firstpost.pub \
    --to=sahu@firstpost.pub \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).