Notes, summaries, assignments, exams, and exercises for Computer science for Other courses

Building C Socket Communication: Server and Client

Computer science2.33 KB

C Socket Server Implementation

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>

#define PORT 8080
#define BUFFER_SIZE 1024

int main() {
    int server_fd, new_socket;
    struct sockaddr_in address;
    int addrlen = sizeof(address);
    char buffer[BUFFER_SIZE] = {0};

    if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
        perror("socket failed");
        exit(EXIT_FAILURE);
    }

    address.sin_family = AF_INET;
    address.sin_addr.s_addr = INADDR_ANY;
    address.sin_port = htons(PORT);

    if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) {
        perror("bind failed");
        exit(EXIT_FAILURE);
    }
...
Continue reading "Building C Socket Communication: Server and Client" »

Software, Hardware, Networking, Cloud & IoT Fundamentals

Computer science2.96 KB

Software

Software: It's a set of instructions, data, or programs used to operate computers and execute specific tasks. It is a generic term used to refer to applications, software, and programs that run on a device. E.g. Excel, Linux, macOS.

Hardware

Hardware: It's the physical parts of a computer and related devices. They can be internal, such as: motherboard, RAM, CPU; or external, such as monitors, printers, and keyboards.

Client/Server Computing

Client/Server Computing: This is a distributed computing model where some processing power is located within small, cost-effective client PCs.

Packet Switching

Packet Switching: Packet switching is a method of breaking down digital messages into smaller packets. These packets are sent across various communication...

Continue reading "Software, Hardware, Networking, Cloud & IoT Fundamentals" »

Comenzi UNIX esențiale: Redirecționare, Find, Grep și Variabile

Computer science3.2 KB

Redirecționarea comenzilor UNIX

  • comanda < fis_in — datele de intrare pentru comandă vor fi preluate din fis_in.
  • comanda > fis_out — datele de ieșire vor fi puse în fis_out cu suprascriere.
  • comanda >> fis_out — datele de ieșire vor fi puse în fis_out cu adăugare.
  • comanda1 | comanda2 — datele pentru comanda 2 vor fi cele rezultate din comanda 1.

Comanda FIND: Căutare după nume

Exemplu: find / -name *.c

  • Tipuri fișier (-type): b - block, c - character, d - directory, f - file, p - FIFO, l - symbolic link.
  • Permisiuni (-perm 664): 1 = Ausführung (execuție), 2 = Schreiben (scriere), 4 = Lesen (citire). Există și 0 = keine Erlaubnis (fără permisiune).
  • / — căutare globală.
  • . — căutare sub directorul curent.

Parametri

...
Continue reading "Comenzi UNIX esențiale: Redirecționare, Find, Grep și Variabile" »

Traffic Server Client Request and Response API Functions

Computer science5.13 KB

Traffic Server Client Request and Response API Functions

This document describes the Traffic Server API functions related to client requests and responses.

Client Request Functions

FunctionDescription
ts.client_request.get_methodRetrieves the current client request's method name. Returns a string like "GET" or "POST".
ts.client_request.set_methodOverrides the current client request's method with METHOD_NAME.
ts.client_request.get_versionReturns the HTTP version string of the client request.
ts.client_request.set_versionSets the HTTP version of the client request with the VERSION_STR.
ts.client_request.get_uriRetrieves the client request's path.
ts.client_request.set_uriOverrides the client request's path.
ts.client_request.get_uri_argsRetrieves the client
...
Continue reading "Traffic Server Client Request and Response API Functions" »

Java Binary Tree Methods for World Entity Management

Computer science4.28 KB

Practica 6: World Class Implementation

This implementation focuses on managing entities within a World data structure using a binary tree approach.

Method: insert

The insert method handles the placement of an Entity at a specific address.

public void insert(String address, Entity e) {
    if (content == null) escribirContenido(content, e, address);
    if (address.equals("")) escribirContenido(content, e, address);
    else {
        if (address.substring(0, 1).equals("L")) {
            address = address.substring(1, address.length());
            travelLeft().insert(address, e);
        } else {
            address = address.substring(1, address.length());
            travelRight().insert(address, e);
        }
    }
}

Method: escribirContenido

A...

Continue reading "Java Binary Tree Methods for World Entity Management" »

Security Essentials: Certificates, Identity, and Access Control

Computer science3.09 KB

1. Cookies: Temporary data stored on the client-side, encrypted if SSL is used.

2. Types of Certificates:

  • Site
  • Personal
  • Software Vendor
  • Anonymous

3. Identity: Used for:

  • Authentication
  • Accountability
  • Identifying principle

4. Principal: A unique identity. Identity is used to identify the principal, which is a computer representation of an entity.

5. Goals of a Certificate Regarding Identity: To bind the correct identity to a distinguished name.

6. Malicious Logic: A set of instructions that cause a site's security policy to be violated.

7. Predictable Computer Usage Patterns: Yes, my usage is statistically predictable. I often work from home, so the patterns between work and home are similar. I check email, run the browser, run Visual Studio, NetBeans, a...

Continue reading "Security Essentials: Certificates, Identity, and Access Control" »

Java Object-Oriented Programming: Quadrado, Piramide, and Cubo

Computer science3.24 KB

Java Geometric Shapes Implementation

abstract class Quadrado {
private float lado;

public Quadrado ()
{this.lado = 0;}

public Quadrado (float lado)
{this.lado = lado;}

public float getLado ()
{return (this.lado);}

public void setLado (float lado)
{this.lado = lado;}

double area ()
{return Math.pow (this.lado,2);}

double perimetro ()
{return 4 * this.lado;}

void mostrarDados ()
{System.out.println ("Quadrado com lado " + this.lado);
System.out.println ("Area = " + this.area ());
System.out.println ("Perimetro = " + this.perimetro());
}
}

class Piramide extends Quadrado {
private float altura;

public Piramide ()
{super (0);
this.altura = 0;}

public Piramide (float lado, float altura)
{super (lado);
this.altura = altura;}

public void setAltura (...

Continue reading "Java Object-Oriented Programming: Quadrado, Piramide, and Cubo" »

Java Polimorfismo: Figuras Planas, Herança e Classes Abstratas

Computer science4.71 KB

Figuras Planas em Java: Herança e Polimorfismo

Este exemplo demonstra o uso de herança, polimorfismo e vinculação dinâmica em Java, por meio de uma hierarquia de classes de figuras planas.

Classe Base: FiguraPlana

class FiguraPlana {
    double area() {
        return 0;
    } // será corrigido com Classes Abstratas

    double perimetro() {
        return 0;
    }

    void mostrarDados() {
        System.out.println("\nNome do Objeto: " + this.toString());
        System.out.println("\nÁrea = " + this.area());
        System.out.println("\nPerímetro = " + this.perimetro());
    }
}

Classe Retangulo

class Retangulo extends FiguraPlana {
    private float ladoA;
    private float ladoB;

    public Retangulo(float ladoA, float ladoB) {
...
Continue reading "Java Polimorfismo: Figuras Planas, Herança e Classes Abstratas" »

Java Theater Simulation Source Code Using Collections

Computer science5.06 KB

Java Theater Management Source Code

Below is the complete, fixed Java source code for managing theater attendees using various data structures like lists, queues, and stacks.

public class Teatro {
    private static File archivo;
    private static FileReader fr;
    private static BufferedReader br;
    private static List<Espectador> listaEspectadores = new ArrayList<>();
    private static Queue<Espectador> colaEspectadores = new ArrayDeque<>();
    private static Stack<Espectador> teatro = new Stack<>();

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            archivo = new File("C:\\Users\\Criscriscris\\Documents\\NetBeansProjects\
...
Continue reading "Java Theater Simulation Source Code Using Collections" »

Integração SQL Server e C# com SqlClient e DataAdapter

Computer science4.68 KB

Criação da Tabela no SQL Server

No banco SQL Server, execute o seguinte script para criar a tabela de CNH:

CREATE TABLE [dbo].[CNH](
    [identificador] [int] IDENTITY(1,1) NOT NULL,
    [numero] [varchar](250) NULL,
    [dataEmissao] [datetime] NULL,
    [dataValidade] [datetime] NULL,
    [categoriaCNH] [varchar](2) NOT NULL,
    [pessoa] [int] NOT NULL,
    CONSTRAINT [PK_CNH] PRIMARY KEY CLUSTERED 
    (
        [identificador] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Implementação do Código em C#

No código C#, utilize a classe SqlConnection para gerenciar as operações de banco de dados:

using System;
using System.Collections.
...
Continue reading "Integração SQL Server e C# com SqlClient e DataAdapter" »