Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Client-Server communication w/ protobuf #89

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ build/
ShangEn/build/*
BenHall/lab1/build
RishiB/build/*
.idea/
hellolib/
lab2part3/
goltsmannn2/part2/result
goltsmannn2/.idea
mitchellcomer/.vscode/*
mitchellcomer/result
Ujaan/Lab-2/Part-1/build/*
Expand Down
18 changes: 18 additions & 0 deletions goltsmannn2/part3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.0)
project(SoftwareOnboardingLab3)
find_package(Protobuf REQUIRED)

add_library(bufferLibrary STATIC src/protobuf.pb.cc)
target_include_directories(bufferLibrary PUBLIC include)
target_link_libraries(bufferLibrary PUBLIC protobuf::libprotobuf)


add_executable(client client.cpp)
add_executable(server server.cpp)


target_link_libraries(client PUBLIC bufferLibrary)
target_link_libraries(server PUBLIC bufferLibrary)

install(TARGETS client DESTINATION bin)
install(TARGETS server DESTINATION bin)
35 changes: 35 additions & 0 deletions goltsmannn2/part3/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <protobuf.pb.h>

#define PORT 8000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically it is best to not use #define for variables, you can use const or static const for these, or for this you can just set the number directly without making a #define.



int main(){
const int clientSocket = socket(AF_INET, SOCK_STREAM, 0);

sockaddr_in serverAddress;
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons(PORT);
serverAddress.sin_addr.s_addr = INADDR_ANY;

connect(clientSocket, (struct sockaddr*)&serverAddress, sizeof(serverAddress));
OnboardingLab3::SimpleMessage message;
std::string name, msg;
std::cin >> name >> msg;
message.set_sender_name(name);
message.set_sender_message(msg);
std::string test;
message.SerializeToString(&test);
send(clientSocket, test.c_str(), test.size(), 0);
close(clientSocket);

return 0;
}

9 changes: 9 additions & 0 deletions goltsmannn2/part3/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ stdenv, cmake, protobuf}:

stdenv.mkDerivation rec {
pname = "software_onboarding_lab_3_package";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [cmake];
buildInputs = [ protobuf ];
}
27 changes: 27 additions & 0 deletions goltsmannn2/part3/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions goltsmannn2/part3/flake.nix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by chance have you tried cross compiling yet? others have been having issues with the step of cross compilation on aarch64-darwin and it would be awesome if yall could group up and help each other through figuring out a fix for it <3 @BANANAPEEL202 @skyraal

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
description = "software_onboarding_lab_3_flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs = { self, nixpkgs, ...} @inputs:
let
system = "aarch64-darwin";
overlay = final: prev: {
defaultPackage = final.callPackage ./default.nix {};
};
overlays = [overlay];
pkgs = import nixpkgs {
system = system;
overlays = [self.overlays.default];
};
in
{
overlays.default = nixpkgs.lib.composeManyExtensions overlays;
packages.${system}.default = pkgs.defaultPackage;
legacyPackages.${system} =
import nixpkgs {
inherit system;
inherit overlays;
};
};
}
Loading