GoMalDev
Overview
GoMalDev is a Go package that provides functions to connect to a server, receive messages from the server, send messages to the server, and get information about the number of CPUs.
Installation
To install GoMalDev, run the following command:
go get github.com/user/gomalde
Usage
To use GoMalDev, import the package into your Go program:
import "github.com/user/gomalde"
Connecting to a Server
The Conectar_c
function connects to a server at the specified IP address and port. The function will continue to try to connect until it is successful.
func Conectar_c(IP string, PORT int) {
for i := 0; i == 0; {
var err error
conn, err = net.Dial("tcp", fmt.Sprintf("%s:%d", IP, PORT))
if err != nil {
i = 0
}
i = 1
}
}
Receiving Messages from the Server
The Receptor_msg_c
function receives messages from the server. The function reads up to 4096 bytes from the server and returns the message as a string.
func Receptor_msg_c() string {
buffer := make([]byte, 4096)
lector, err := conn.Read(buffer)
if err != nil {
msg := fmt.Sprintf("Error: %s", err)
return msg
}
SALIDA := string(buffer[:lector])
return SALIDA
}
Sending Messages to the Server
The Enviar_msg_c
function sends messages to the server. The function writes the message to the server and returns a boolean indicating whether the message was sent successfully.
func Enviar_msg_c(msg string) bool {
_, err := conn.Write([]byte(msg))
return err == nil
}
The NucleoInfo
function gets information about the number of CPUs. The function returns the number of CPUs as a string.
func NucleoInfo() string {
NCpu := runtime.NumCPU()
fmt.print(NCpu)
Comment and Documentacion Generated by BlackboxAI