Created
June 17, 2013 21:14
-
-
Save anonymous/5800518 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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