source code migrating from gitlab
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:net"
|
||||
//import "core:os"
|
||||
|
||||
main :: proc() {
|
||||
|
||||
//args := os.args
|
||||
//for arg in args {
|
||||
// fmt.println(arg)
|
||||
//}
|
||||
//fmt.printf("hello! %s\n", "world")
|
||||
server("127.0.0.1", 5500)
|
||||
}
|
||||
|
||||
server :: proc(ip: string, port: int) {
|
||||
|
||||
addr, ok := net.parse_ip4_address(ip)
|
||||
if !ok {
|
||||
fmt.println("could not parse address")
|
||||
return
|
||||
}
|
||||
|
||||
endpoint := net.Endpoint {
|
||||
address = addr,
|
||||
port = port,
|
||||
}
|
||||
|
||||
sock, err := net.listen_tcp(endpoint)
|
||||
if err != nil {
|
||||
fmt.printf("error creating sock fd: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer net.close(sock)
|
||||
|
||||
for {
|
||||
client, src, err := net.accept_tcp(sock)
|
||||
if err != nil {
|
||||
fmt.println("error accepting client", err)
|
||||
continue
|
||||
}
|
||||
fmt.println("src: ", src)
|
||||
handleClient(client)
|
||||
}
|
||||
}
|
||||
|
||||
handleClient :: proc(sock: net.TCP_Socket) {
|
||||
defer net.close(sock)
|
||||
|
||||
|
||||
buffer: [2048]u8
|
||||
|
||||
bytes, err := net.recv_tcp(sock, buffer[:])
|
||||
if err != nil {
|
||||
fmt.println("error recv", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.printf("%s\n", buffer)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
# Odin
|
||||
|
||||
|
||||
## For Learning Only
|
||||
|
||||
These little projects are for learning only and you can see the videos: [here](https://www.youtube.com/@aveydotdev)
|
||||
|
||||
|
||||
## Collaborate
|
||||
|
||||
Feel free to reach out if something isn't write or there's an update to Odin that could benefit someone learning Odin. Thanks!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user