Integrate client as variable in server class
This commit is contained in:
parent
b6468bd148
commit
1f82e94296
@ -15,6 +15,11 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
class client;
|
||||||
|
// class secure;
|
||||||
|
// class server;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server klasa za TCP/IP soket
|
* Server klasa za TCP/IP soket
|
||||||
* Instanca se incijalizira kada pokrećemo server
|
* Instanca se incijalizira kada pokrećemo server
|
||||||
@ -24,13 +29,14 @@ class server {
|
|||||||
public:
|
public:
|
||||||
int sock;
|
int sock;
|
||||||
struct sockaddr_in addr;
|
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 ();
|
~server ();
|
||||||
|
|
||||||
// dok god živi server žive i klijenti - klijetni moraju biti dio servera
|
// one klijent
|
||||||
// omogućiti enkripciju i na nivou servera
|
client* cli;
|
||||||
|
void accept(const uint timeout = 100);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,6 +66,8 @@ class client {
|
|||||||
int conn; // mijenja sock
|
int conn; // mijenja sock
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
SSL* ssl = NULL;
|
SSL* ssl = NULL;
|
||||||
|
// server s klijentima
|
||||||
|
const server* srv;
|
||||||
// klijent sa serverom
|
// klijent sa serverom
|
||||||
string ipv4;
|
string ipv4;
|
||||||
string ipv6;
|
string ipv6;
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
* Kontrustruktor varijable tipa server, prima port i limit za ograničenje liste klijenata na čekanju
|
* 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_family = AF_INET;
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
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
|
* Destruktor varijable tipa server
|
||||||
*/
|
*/
|
||||||
@ -38,6 +43,9 @@ server::server (const ushort port, const uint limit) {
|
|||||||
|
|
||||||
server::~server () {
|
server::~server () {
|
||||||
|
|
||||||
|
cli->~client();
|
||||||
|
cli = NULL;
|
||||||
|
|
||||||
if (sock<=0) {
|
if (sock<=0) {
|
||||||
throw string("[ERROR] The socket is already closed ");
|
throw string("[ERROR] The socket is already closed ");
|
||||||
}
|
}
|
||||||
|
BIN
test/client.o
BIN
test/client.o
Binary file not shown.
@ -6,21 +6,26 @@ using namespace std;
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try{
|
try{
|
||||||
cout << "init server " << endl;
|
|
||||||
server myserver(5000);
|
|
||||||
cout << "init cert " << endl;
|
cout << "init cert " << endl;
|
||||||
secure crypto ("../example/cert.pem", "../example/privkey.pem");
|
secure crypto ("../example/cert.pem", "../example/privkey.pem");
|
||||||
|
cout << "init server " << endl;
|
||||||
|
server myserver(5000, 100, crypto.fds);
|
||||||
|
|
||||||
cout << "init client " << endl;
|
cout << "init client " << endl;
|
||||||
|
|
||||||
client myclient(&myserver, 100, crypto.fds);
|
// client myclient(&myserver, 100, crypto.fds);
|
||||||
// comming myclient(&myserver, 100);
|
// 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;
|
cout << "tell client " << fromclient << endl;
|
||||||
// usleep(600*1000);
|
// usleep(600*1000);
|
||||||
sleep(5);
|
sleep(5);
|
||||||
myclient.push(fromclient);
|
myserver.cli->push(fromclient);
|
||||||
|
// myclient.push(fromclient);
|
||||||
// myclient.~comming();
|
// myclient.~comming();
|
||||||
|
|
||||||
// while (true) {
|
// while (true) {
|
||||||
|
BIN
test/server.o
BIN
test/server.o
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user