working tcp comm

This commit is contained in:
2019-04-27 22:29:33 -05:00
parent 3ad3d73a2f
commit 3f2d84e8d4
10 changed files with 166 additions and 99 deletions
+37 -36
View File
@@ -5,59 +5,60 @@
#include <functional>
#include <sstream>
#include <vector>
#include <thread>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include "common.hpp"
namespace betacore{
namespace betacore
{
class Client
{
private:
bool _online = false;
bool _running = false;
char key = 'Z';
int _port;
std::string _url;
MODE _mode;
int _client_socket;
std::function<void(SHAPE &S)> _update;
struct sockaddr_in _server_address;
struct hostent *_server;
std::map<std::string, std::string> lookup;
std::string encode(const SHAPE &shape);
std::string crypt(const std::string &shape);
class Client{
private:
bool _online = false;
bool _running= false;
char key = 'Z';
int _port;
std::string _address;
MODE _mode;
int _client_socket;
std::function<void(SHAPE &S)> _update;
struct sockaddr_in _server_address;
struct hostent * _server;
std::string raw(const SHAPE &shape);
SHAPE parse(const std::string &message);
std::string encode(const SHAPE &shape);
std::string crypt(const std::string &shape);
std::string raw(const SHAPE &shape);
SHAPE parse(const std::string &message);
SHAPE decode(const std::string &message);
/**
SHAPE decode(const std::string &message);
/**
* Function for Thread for getting information from server
*/
void listener();
/**
void listener();
/**
* Function for Thread for sending to server
*/
void sender();
void start();
void stop();
public:
Client(MODE mode, int port, std::string address, std::function<void(SHAPE &S)> &update);
void kill();
bool running();
void send(bool encrypt, SHAPE shape);
void sender();
void start();
void stop();
public:
Client(MODE mode, int port, std::string url, std::function<void(SHAPE &S)> &update);
void kill();
bool running();
void send(bool encrypt, SHAPE shape);
};
}
} // namespace betacore
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef __BETACORE_COMMON_HPP__
#define __BETACORE_COMMON_HPP__
#define BUFFER_SIZE 1024
namespace betacore
{
enum SHAPE{
+15 -3
View File
@@ -1,14 +1,26 @@
#ifndef __BETACORE_SERVER_HPP__
#define __BETACORE_SERVER_HPP__
#include <vector>
#include <algorithm>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/poll.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <thread>
#include <utility>
#include <functional>
#include "common.hpp"
namespace betacore
{
@@ -16,14 +28,13 @@ namespace betacore
class Server
{
private:
fd_set rset;
bool online = false;
bool server_running= false;
int port;
int server_socket;
std::vector<int> clients;
char buffer[1024];
struct sockaddr_in server_address;
std::vector<sockaddr_in> client_socket_collection;
void start();
void shutdown();
void listener();
@@ -32,6 +43,7 @@ public:
Server(int port);
void off();
bool running();
};
} // namespace betacore