Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2013 21:14
Show Gist options
  • Save anonymous/5800518 to your computer and use it in GitHub Desktop.
Save anonymous/5800518 to your computer and use it in GitHub Desktop.
// Server.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <chrono>
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#ifndef WIN32
#include <signal.h>
#endif
using namespace std;
void newConnection(SocketStream A, int conID)
{
A.SetProtocolMode(static_cast<SocketStream::ProtocolMode>(SocketStream::PM_DISGUISE_SERVER | SocketStream::PM_Encrypted));
SocketStream temp;
if (A.isConnected())
{
#if LOGLEVEL > 0
SOCKSRelay(A,temp,QUEUESIZE,SOCKSRelay::PM_socks_uninitilized,conID);
#else
SOCKSRelay(A,temp,QUEUESIZE,SOCKSRelay::PM_socks_uninitilized);
#endif
}
}
int main(int argc, char* argv[])
{
#if LOGLEVEL > 0
system("rm -f ../Log/*.txt");
#endif
ServerSocketStream server;
if(!server.bind(8008))
{
cout << "port is already in use\n";
return 1;
}
server.SetBlockMode(SocketStream::BM_ALWAYS);
int threadID = 0;
SocketStream A;
int conID = 0;
#ifndef WIN32
signal(SIGPIPE,SIG_IGN);
#endif
#if LOGLEVEL > 0
thread ([](){
while(true)
{
cout << "workers : " << SOCKSRelay::activeWorkers << "\n";
cout.flush();
this_thread::sleep_for(chrono::milliseconds(500));
}
}).detach();
SOCKSRelay::appname = "ser";
#endif
while (true)
{
SocketStream A=server.waitForNewConnection();
thread(newConnection,A,conID++).detach();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment