Lab2_26042023

This commit is contained in:
mrshitovsasha 2023-04-26 19:33:05 +03:00
commit 0d978dde5a
3 changed files with 72 additions and 0 deletions

16
SOFIA.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SOFIA</title>
<link rel="stylesheet" href="https://stackedit.io/style.css" />
</head>
<body class="stackedit">
<iframe width="560" height="315" src="https://www.youtube.com/embed/u2rwFpqlXjw" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</body>
</html>

28
files.js Normal file
View File

@ -0,0 +1,28 @@
const http = require('http');
const fs = require('fs');
const server = http.createServer((req, res) => {
//console.log(req)
fs.readFile('./'+req.url, (err, data) => {
if(err){
res.writeHead(404, "Not Found");
res.write("No file found");
res.end();
} else {
res.writeHead(200, {
'Content-Length': data.length,
'Content-Type': 'text/html'
})
res.write(data);
res.end();
}
});
});
server.on('clientError', (err, socket) => {
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
});
server.listen(8088, () => {
console.log("listen on http://localhost:8088/");
});

28
index.js Normal file
View File

@ -0,0 +1,28 @@
const net = require('net');
const fs = require('fs');
const server = net.createServer((c) => {
// 'connection' listener.
console.log('client connected');
c.on('end', () => {
console.log('client disconnected');
});
//c.write('HTTP/1.1 200 OK\r\nContent-Length: 12\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nHello World!');
fs.readFile('./SOFIA.html', (err, data) => {
c.write('HTTP/1.1 200 OK\r\n');
c.write('Content-Length: '+data.length+'\r\n');
c.write('Content-Type: text/html; charset=utf-8\r\n');
c.write('\r\n');
c.write(data);
});
//c.pipe(c);
c.on('data', (data) => {
console.log(data.toString());
})
});
server.on('error', (err) => {
throw err;
});
server.listen(8124, () => {
console.log('server bound');
});