Skip to content

Instantly share code, notes, and snippets.

View AryanGodara's full-sized avatar
🧏
BYE🤫BYE🧏

Aryan Godara AryanGodara

🧏
BYE🤫BYE🧏
View GitHub Profile
@AryanGodara
AryanGodara / udpserver.ml
Created July 6, 2023 11:45
UDP server implementation in OCaml
open Lwt
(* Shared mutable counter *)
let counter = ref 0
let listen_address = Unix.inet_addr_loopback
let port = 9000
let backlog = 10
@AryanGodara
AryanGodara / math.proto
Created July 17, 2023 17:55
math.proto
syntax = "proto3";
option go_package = "gihthub.com/aryangodara/go-kit-grpc-example1/pb";
service MathService {
rpc Add(MathRequest) returns (MathResponse);
rpc Subtract(MathRequest) returns (MathResponse);
rpc Multiply(MathRequest) returns (MathResponse);
rpc Divide(MathRequest) returns (MathResponse);
}
@AryanGodara
AryanGodara / service.go
Last active July 17, 2023 18:17
service/service.go
package service
import (
"context"
"github.com/go-kit/log"
)
type service struct {
logger log.Logger
@AryanGodara
AryanGodara / endpoints.go
Created July 17, 2023 18:19
endpoints/endpoints.go
package endpoints
import (
"context"
"github.com/aryangodara/go-kit-grpc-example1/api/service"
"github.com/go-kit/kit/endpoint"
)
// Endpoints struct holds a list of endpoints
@AryanGodara
AryanGodara / grpcTransport.go
Created July 17, 2023 18:22
transports/grpcTransport.go
package transports
import (
"context"
"errors"
"github.com/aryangodara/go-kit-grpc-example1/api/endpoints"
"github.com/aryangodara/go-kit-grpc-example1/pb"
gt "github.com/go-kit/kit/transport/grpc"
"github.com/go-kit/log"
@AryanGodara
AryanGodara / main.go
Created July 17, 2023 18:23
cmd/main.go
package main
import (
"fmt"
"net"
"os"
"os/signal"
"syscall"
"github.com/aryangodara/go-kit-grpc-example1/api/endpoints"
@AryanGodara
AryanGodara / client.ml
Created July 21, 2023 20:52
udpClient/bin/client.ml
open Lwt.Infix
let listen_address = Unix.inet_addr_loopback
let port = 9000
let handle_message msg =
print_endline ("Received message in handle_message: " ^ msg);
match msg with "quit" -> "quit" | _ -> "Ready for next message"
let rec handle_request server_socket =
@AryanGodara
AryanGodara / main.ml
Created July 21, 2023 20:55
udpClient/bin/main.ml
let () =
print_endline "Launching UDP Client...";
let () = Logs.set_reporter (Logs.format_reporter ()) in
let () = Logs.set_level (Some Logs.Info) in
let client_socket = Client.create_socket () in
Lwt_main.run Client.(create_client client_socket)
@AryanGodara
AryanGodara / main.ml
Created July 21, 2023 21:04
udpServer/bin/main.ml
let () =
print_endline "Launching UDP Server...";
let () = Logs.set_reporter (Logs.format_reporter ()) in
let () = Logs.set_level (Some Logs.Info) in
let server_socket = Server.create_socket () in
Lwt_main.run Server.(create_server server_socket)
@AryanGodara
AryanGodara / server.ml
Created July 21, 2023 21:05
udpServer/bin/server.ml
open Lwt.Infix
(* Shared mutable counter *)
let counter = ref 0
(* This defines a shared mutable counter initialized to 0 using a reference cell. *)
let listen_address = Unix.inet_addr_loopback
(* This sets the listen_address to the loopback IP address (127.0.0.1), indicating
that the server will listen for connections from the local machine only. *)