-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from all commits
39f60a8
602481d
46d9654
bbe8ba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
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 | ||
|
||
|
||
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; | ||
} | ||
|
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 ]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}; | ||
}; | ||
} |
There was a problem hiding this comment.
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 useconst
orstatic const
for these, or for this you can just set the number directly without making a#define
.