This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import socket | |
| import selectors | |
| import types | |
| # Create you selector that will | |
| # be used for IO multiplexing | |
| sel = selectors.DefaultSelector() | |
| # Client messages | |
| messages = [b"Message 1 from client", b"Message 2 from client"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| void incr(int *x){ | |
| *x += 1; | |
| } | |
| int main(){ | |
| // initialize i to be equal to 6 | |
| int i = 6; | |
| printf("i = %d\n", i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CMakeLists.txt | |
| cmake_minimum_required(VERSION 3.10) | |
| project(EchoServerClient) | |
| # Server executable | |
| add_executable(server server.c) | |
| # Client executable | |
| add_executable(client client.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <unistd.h> | |
| #include <arpa/inet.h> | |
| #define MAX_BUFFER_SIZE 1024 | |
| //Function prototypes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| int main() { | |
| // Create a buffer | |
| char helloBuffer[50]; | |
| // Using snprintf to create the "Hello, World" string | |
| snprintf(helloBuffer, sizeof(helloBuffer), "Hello, %s!\n", "World"); | |
| printf("%s", helloBuffer); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <string.h> | |
| #include <sys/wait.h> | |
| int main() { | |
| int pipefd[2]; // File descriptors for the pipe | |
| // Create the pipe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| int main() { | |
| pid_t pid = fork(); | |
| if (pid == -1) { | |
| perror("Fork failed"); | |
| return 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from html.parser import HTMLParser | |
| class SimpleHTMLParser(HTMLParser): | |
| def __init__(self): | |
| super().__init__() | |
| self.dom_tree = [] | |
| def handle_starttag(self, tag, attrs): | |
| element = {'tag': tag, 'attributes': dict(attrs), 'content': []} | |
| if not self.dom_tree: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| async def handle_request(reader, writer): | |
| data = await reader.readuntil(separator=b"\r\n\r\n") | |
| message = data.decode() | |
| addr = writer.get_extra_info('peername') | |
| print(f"Received request from {addr}") | |
| print(f"Send response.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http'); | |
| const fs = require('fs'); | |
| const url = require('url'); | |
| // Simulated user data | |
| const users = [ | |
| { id: 1, username: 'john_doe', password: 'password123' }, | |
| { id: 2, username: 'jane_smith', password: 'example456' } | |
| ]; |