minitcpgo

package module
v0.0.0-...-5ae7c3d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 3 Imported by: 0

README

MiniTCPGo: A Simple TCP Client-Server Library in Go

Introduction

MiniTCPGo is a simple TCP client-server library written in Go. It provides basic functionality for connecting to a TCP server, sending and receiving messages, and retrieving information about the system's CPU count.

Installation

To install MiniTCPGo, simply clone the repository and import the minitcpgo package into your Go project.

UNDER PROJECT

Usage

Client

To use MiniTCPGo as a client, you will need to create a connection to the server using the Conectar_c function. This function takes two arguments: the IP address of the server and the port number.

import "minitcpgo"

func main() {
    // Connect to the server at 127.0.0.1:8080
    minitcpgo.Conectar_c("127.0.0.1", 8080)

    // Send a message to the server
    minitcpgo.Enviar_msg_c("Hello, world!")

    // Receive a message from the server
    msg := minitcpgo.Receptor_msg_c()

    // Print the message to the console
    fmt.Println(msg)
}
Server

To use MiniTCPGo as a server, you will need to create a listener using the net.Listen function. This function takes two arguments: the network type (in this case, "tcp") and the address to listen on.

import (
    "fmt"
    "net"
    "minitcpgo"
)

func main() {
    // Create a listener on port 8080
    listener, err := net.Listen("tcp", ":8080")
    if err != nil {
        fmt.Println(err)
        return
    }

    // Accept connections from clients
    for {
        conn, err := listener.Accept()
        if err != nil {
            fmt.Println(err)
            continue
        }

        // Handle the connection in a separate goroutine
        go minitcpgo.HandleConnection(conn)
    }
}

Generated by BlackboxAI

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conectar_c

func Conectar_c(IP string, PORT int)

function to connect to the server

func Enviar_msg_c

func Enviar_msg_c(msg string) bool

function to send messages to the server

func NucleoInfo

func NucleoInfo() string

NucleoInfo returns information about the system's CPU count

func Receptor_msg_c

func Receptor_msg_c() string

function to receive messages from the server

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL