Simple TCP socket library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
socket/test/server.cpp

81 lines
2.7 KiB

1 year ago
#include <iostream>
#include "../lib/tcp_socket.hpp"
using namespace std;
int main() {
try{
// cout << "init cert " << endl;
// secure crypto ("../example/cert.pem", "../example/privkey.pem");
// cout << "init server " << endl;
// server myserver(5000, 100, crypto.fds);
12 months ago
// cout << "init cert " << endl;
// secure crypto ("../example/cert.pem", "../example/privkey.pem");
// cout << "init server " << endl;
// server myserver(8000, 100, crypto.fds);
// cout << "init client " << endl;
// // client myclient(&myserver, 100, crypto.fds);
// // comming myclient(&myserver, 100);
// myserver.accept();
// // cout << "wait client " << myclient.ipv4 << endl;
// cout << "wait client " << myserver.cli->ipv4 << endl;
// string fromclient = myserver.cli->pull();
// // string fromclient = myclient.pull();
// cout << "tell client " << fromclient << endl;
// // usleep(600*1000);
// sleep(5);
// myserver.cli->push(fromclient);
12 months ago
// string fromclient = myserver.cli->pull();
// string fromclient = myclient.pull();
12 months ago
// cout << "tell client " << fromclient << endl;
// usleep(600*1000);
//sleep(5);
12 months ago
// myserver.cli->push(fromclient);
// myclient.push(fromclient);
// myclient.~comming();
// while (true) {
// comming myclient(&myserver, 1000);
// string fromclient = myclient.obey();
// cout << fromclient << " " << myclient.conn << endl;
// cout << "Poslano: " << myclient.tell(fromclient) << "Veličin: " << fromclient.length() << endl;
// // myclient.~comming();
// cout << "IPv4 " << myclient.ipv4 << " ipv6 " << myclient.ipv6;
// }
// sleep(80);
server myserver(5000, 100);
myserver.async(8, [](client &cli, mutex &io) {
cout << "Klijent " << cli.ipv4 << endl;
string fromclient = cli.pull();
12 months ago
// io.lock();
cout << "S klijenta " << fromclient << endl;
12 months ago
// io.unlock();
// fromclient += teststr;
cli.push(fromclient);
12 months ago
}, 0);
// string teststr = " Idemooo";
// myserver.sync([](client &cli, mutex &io) {
// cout << "Klijent " << cli.ipv4 << endl;
// string fromclient = cli.pull();
// io.lock();
// cout << "S klijenta " << fromclient << endl;
// io.unlock();
// // fromclient += teststr;
// cli.push(fromclient);
// });
}
catch(const string err) {
cout << err << endl;
}
1 year ago
return 0;
}