4 files wounded 0 dead

This commit is contained in:
malloc 2018-04-03 17:03:45 -05:00
parent f238152970
commit 0425488769
4 changed files with 15 additions and 7 deletions

View file

@ -34,8 +34,6 @@ int main(int argc, char **argv) {
client.Handshake();
else
break;
//client.Receive(&buffer, SOSC_TCP_BLOCK);
//std::cout << buffer;
}
server.Close();

View file

@ -53,16 +53,24 @@ int sosc::ScapeConnection::Handshake() {
return SOSC_SHAKE_ERR;
}
websocket_key += "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
websocket_key = cgc::base64_encode(cgc::sha1(websocket_key, true));
std::stringstream stream;
stream << "HTTP/1.1 101 Switching Protocols\r\n"
<< "Upgrade: websocket\r\n"
<< "Connection: Upgrade\r\n"
<< "Sec-WebSock";
<< "Sec-WebSocket-Accept: " << websocket_key << "\r\n\r\n";
this->client.Send(stream.str());
this->handshaked = true;
return SOSC_SHAKE_DONE;
}
sosc::ScapeConnection::~ScapeConnection() {
this->Close();
}
/******************************/
/* END SCAPECONNECTION CODE */
/******************************/

View file

@ -1,6 +1,8 @@
#ifndef SOSC_SCAPESOCK_H
#define SOSC_SCAPESOCK_H
#include "../crypto/sha1.hpp"
#include "../crypto/base64.hpp"
#include "packet.hpp"
#include "tcpsock.hpp"

View file

@ -223,9 +223,9 @@ bool sosc::TcpServer::Listen(uint16_t port) {
return true;
}
int sosc::TcpServer::Accept(TcpClient* client) {
bool sosc::TcpServer::Accept(TcpClient* client) {
if(!this->sock_open)
return -1;
return false;
SOSC_SOCK_T sock;
SOSC_ADDR_T addr;
@ -234,12 +234,12 @@ int sosc::TcpServer::Accept(TcpClient* client) {
sock = accept(this->sock, (struct sockaddr*)&addr, &addr_len);
if(sock == INVALID_SOCKET) {
this->Close();
return -1;
return false;
}
client->Close();
client->Open(sock, addr, addr_len);
return 0;
return true;
}
void sosc::TcpServer::Close() {