導航:首頁 > 配伺服器 > shadowsock如何搭建伺服器

shadowsock如何搭建伺服器

發布時間:2023-08-17 09:54:37

A. Socket編程如何搭建一個外網可以訪問的伺服器

步驟:
1,和代理建立tcp聯接。
2,向代理發送版本的請求信息:
void CCommunicator::SendVer()
{
int datasize = 6;
char tempbuf[6];
tempbuf[0]=5;
tempbuf[1]=4;//標示後面所根的字接數
tempbuf[2]=0;
tempbuf[3]=1;
tempbuf[4]=2;
tempbuf[5]=3;
int senddatalen;
senddatalen=send(m_sock,(char*)tempbuf,6,0);
}
這一步如果失敗,斷開建立的tcp聯接,如果成功,如果需要用戶驗證則進行步驟3,否則進行4.
3,如果需要用戶驗證,則類似:
BOOL CCommunicator::SendUserTest()
{
int usernamelen=0;
int userpasslen=0;
usernamelen=m_strTestUserName.GetLength();
userpasslen=m_strTestUserPass.GetLength();
char tempbuf[100];
tempbuf[0]=5;
tempbuf[1]=usernamelen;//標示後面所根的字接數
strcpy(&tempbuf[2],m_strTestUserName);
tempbuf[2+usernamelen]=userpasslen;
strcpy((char*)&tempbuf [3+usernamelen],m_strTestUserPass);
int senddatalen;
int len;
len=usernamelen+userpasslen+3;
senddatalen=send(m_sock,(char*)tempbuf,len,0);
} 如果失敗,斷開建立的tcp聯接, 如果用戶返回成功,步驟4.
4,發送請求的協議類似:
void CCommunicator::SendRequestUDP()
{
int const datasize=10;
BYTE tempbuf[datasize]; tempbuf[0]=5;
tempbuf[1]=3;//標示UDP連接
tempbuf[2]=0;
tempbuf[3]=1;
tempbuf[4]=0;
tempbuf[5]=0;
tempbuf[6]=0;
tempbuf[7]=0;
*((SHORT*)(&(tempbuf[8])))=m_uBindUDPPort; //UDP在客戶端綁定的埠,就是你本地機器的做udp數據傳送的埠調用
//socket函數後,再調用bind()來邦定一個埠。
char temp;
temp=tempbuf[8];
tempbuf[8]=tempbuf[9];
tempbuf[9]=temp;
int senddatalen=send(m_sock,(char*)tempbuf,datasize,0);
}
如果失敗,斷開建立的tcp聯接,如果返回成功,驗證完畢!步驟5
5,真正的數據傳送,用代理傳送的時候,數據包的前面加上10個位元組類似:
void CCommunicator::CopyDataHead(BYTE * ptempbuf)
{
struct in_addr addr;
addr.s_addr=inet_addr(「202.220.33.333」);//這個ip是伺服器端的ip
ptempbuf[0]=0;
ptempbuf[1]=0;
ptempbuf[2]=0;
ptempbuf[3]=1;
ptempbuf[4]=(char)addr.S_un.S_un_b.s_b1;
ptempbuf[5]=(char)addr.S_un.S_un_b.s_b2;
ptempbuf[6]=(char)addr.S_un.S_un_b.s_b3;
ptempbuf[7]=(char)addr.S_un.S_un_b.s_b4;
*((SHORT*)(&(ptempbuf[8])))=m_uServerUDPPort;//伺服器的埠,就是你最終要發到那個伺服器的埠,也就是你的qq伺服器。
char temp;
temp=ptempbuf[8];
ptempbuf[8]=ptempbuf[9];
ptempbuf[9]=temp;
}
真正發送的時候類似:
int CCommunicator::SendBufferUDP(LPBYTE lpBuf,int nLen)
{
BYTE tempbuf[1000];
int iHeadData=0;
struct sockaddr_in her;
her.sin_family=AF_INET;
her.sin_addr.s_addr=inet_addr(m_szProxyAddr);//代理伺服器
her.sin_port=htons(m_uSocksPort);//發送請求的時候返回的代理伺服器端的埠,記住,這是最重要的。
CopyDataHead(tempbuf);
iHeadData=10;
nLen=nLen+10;
int addr_len;
addr_len=sizeof(struct sockaddr);
CopyMemory((char*)&tempbuf[iHeadData],lpBuf,nLen);
int returndatalen=sendto(m_socket,(char *)tempbuf,nLen,0,(struct sockaddr *)&her,addr_len);

閱讀全文

與shadowsock如何搭建伺服器相關的資料

熱點內容
java配置資料庫連接 瀏覽:479
java多態的體現 瀏覽:554
java的split分隔符 瀏覽:128
跪著敲代碼的程序員 瀏覽:238
web和php有什麼區別 瀏覽:120
加密的電梯卡怎麼復制蘋果手機 瀏覽:218
warez壓縮 瀏覽:137
黑馬程序員培訓機構官網天津 瀏覽:904
mainjavasrc 瀏覽:58
如何買伺服器挖礦 瀏覽:292
php批量上傳文件夾 瀏覽:560
安卓固件怎麼更新 瀏覽:169
單片機代碼常式網站 瀏覽:923
UG編程如何多平面輪廓2D倒角 瀏覽:438
視頻壓縮漸變紋 瀏覽:852
什麼app能看財經新聞 瀏覽:40
數學奇跡神奇運演算法 瀏覽:360
大廠的程序員的水平如何 瀏覽:701
遺傳演算法入門經典書籍 瀏覽:879
源碼炮台腳本 瀏覽:621