Integrate client as variable in server class

cleaning
marcelb 1 year ago
parent b6468bd148
commit 1f82e94296
  1. 16
      lib/tcp_socket.hpp
  2. 10
      src/tcp_socket.cpp
  3. BIN
      test/client.o
  4. 17
      test/server.cpp
  5. BIN
      test/server.o

@ -15,6 +15,11 @@
using namespace std;
class client;
// class secure;
// class server;
/**
* Server klasa za TCP/IP soket
* Instanca se incijalizira kada pokrećemo server
@ -24,13 +29,14 @@ class server {
public:
int sock;
struct sockaddr_in addr;
SSL_CTX* securefds = NULL;
server (const ushort port, const uint limit = 1000);
server (const ushort port, const uint limit = 1000, SSL_CTX* _securefds = NULL);
~server ();
// dok god živi server žive i klijenti - klijetni moraju biti dio servera
// omogućiti enkripciju i na nivou servera
// one klijent
client* cli;
void accept(const uint timeout = 100);
};
@ -60,6 +66,8 @@ class client {
int conn; // mijenja sock
struct sockaddr_in addr;
SSL* ssl = NULL;
// server s klijentima
const server* srv;
// klijent sa serverom
string ipv4;
string ipv6;

@ -4,7 +4,8 @@
* Kontrustruktor varijable tipa server, prima port i limit za ograničenje liste klijenata na čekanju
*/
server::server (const ushort port, const uint limit) {
server::server (const ushort port, const uint limit, SSL_CTX* _securefds) {
securefds = _securefds;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
@ -31,6 +32,10 @@ server::server (const ushort port, const uint limit) {
}
void server::accept(const uint timeout) {
cli = new client(this, timeout, securefds);
}
/**
* Destruktor varijable tipa server
*/
@ -38,6 +43,9 @@ server::server (const ushort port, const uint limit) {
server::~server () {
cli->~client();
cli = NULL;
if (sock<=0) {
throw string("[ERROR] The socket is already closed ");
}

Binary file not shown.

@ -6,21 +6,26 @@ using namespace std;
int main() {
try{
cout << "init server " << endl;
server myserver(5000);
cout << "init cert " << endl;
secure crypto ("../example/cert.pem", "../example/privkey.pem");
cout << "init server " << endl;
server myserver(5000, 100, crypto.fds);
cout << "init client " << endl;
client myclient(&myserver, 100, crypto.fds);
// client myclient(&myserver, 100, crypto.fds);
// comming myclient(&myserver, 100);
cout << "wait client " << myclient.ipv4 << endl;
myserver.accept();
// cout << "wait client " << myclient.ipv4 << endl;
cout << "wait client " << myserver.cli->ipv4 << endl;
string fromclient = myclient.pull();
string fromclient = myserver.cli->pull();
// string fromclient = myclient.pull();
cout << "tell client " << fromclient << endl;
// usleep(600*1000);
sleep(5);
myclient.push(fromclient);
myserver.cli->push(fromclient);
// myclient.push(fromclient);
// myclient.~comming();
// while (true) {

Binary file not shown.
Loading…
Cancel
Save