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