So I'm trying to make a function that creates a socket, and then uses a switch statement in order to decide what it sends out to the server and how to handle what the server sends back.
The data being sent out is a string that has been encrypted using AES-256-CBC(in other words the string won't be sent using normal ASCII characters as far as I can tell), so far there are 3 differant strings that are sent out based on which case the switch statement runs.
However I've never worked with sockets in C++ before so I'm unsure how to really write this function. I was wondering if somebody could help me here with doing this?
This is the current structure I have for the function with its switchstatement
static book checked = false;
staticvoid Socket_Handler(int mode){
switch(mode){
case 0 :
if(checked == true){ //checked is set to true after the first time this is ran
//Handle string 0 being sent and action 0 being performed
checked = true;
}else{
Socket_Handler(1);
}
break;
case 1 :
//Handle string 1 being sent and action 1 being performed
break;
case 2 :
//Handle string 2 being sent and action 2 being performed
break;
}
return;
}
The name of function is send(...) (or sendto(...) depending on kind of connection). It requires a socket 'descriptor' and the buffer containing the data to send. Not too difficult.
FIguring out what libraries I'd need to use on windows and on linux mostly and then how to actually use them. I've used sockets before with NodeJS but C++ seems a bit differant from what I did before
I was hoping that bgnet thing was for some socket library rather than just a guid on networking. I already know how I'm going to be handling data being sent and recieve I just can't seem to find what I need to do it. I'm basically trying to send a string and then recieve a string as a response, store the recieved string, close the connection, handle the string that was recieved and then return out of the function
I don't know tbh, I just know that in node.js I used socket_handler = require("https");
and then I would just send stuff to it using an http.post() (http.Post() was a function available in lua at the time) I'd then convert the msg to a json table when it arived at the NodeJS server.
Currently I'm trying to recreate what I did in lua using C++ instead and have it connect to the same NodeJS server from before. But I'm sorta new to c++ and not sure what to really do with it for recreating this.
The lua function I was using before was for a game called Garry's Mod, however that function was just exposted to lua from inside the engine. So I don't really have source code access to that function to really be able to replicate that or learn from there so its been a slow process trying to figure out how to handle this in c++ myself
I'm a little confused on the usage in this, I'm currently looking at the example for an https get request page https://curl.haxx.se/libcurl/c/https.html (there didn't seem to be an https-post one. only http-post)
I'm confused mainly on what part would be considered the "body" returned from the get request
yea but like I can't tell which portion of the code is the response being sent by the webserver. from what I can tel res is just a response code like 404/200/ect, I can't tell but I'm sure its not curl either
I'm thinking I might have to opt back to sockets most likely. LibCurl seems to be giving some issues trying to send a string and get a string back. Alot of the docs pages seem to keep mentioning things regarding files rather than data being sent and recieved. I'm not sure this is the right library for my use case. that and it keeps running things almost like its async rather than waiting for a response before continueing.
I'm thinking I'm going to opt back to sockets but that brings me back to my original issue of not knowing what library to actually use and having to deal with 2 seperate libraries for Linux and Windows just to send a string and then wait for a string to be sent back
well I now have a kinda slimed down function for using the Networking TS thing for C++
but I'm unsure of a few things in it, I got it from an example on github but the comments were pretty much not there to really explain whats happening with it. I put some comments in where I wasn't 100% sure about what was going on https://pastebin.com/WnqicWFE