導航:首頁 > 配伺服器 > 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如何搭建伺服器相關的資料

熱點內容
豬臉識別app如何下載 瀏覽:154
卓嵐串口伺服器如何使用 瀏覽:438
pdf周振甫 瀏覽:756
程序員35歲生日圖片 瀏覽:626
矩形密封圈的壓縮量 瀏覽:455
信息安全中圖像加密技術畢業論文 瀏覽:536
gear2刷android 瀏覽:79
怎麼用安卓下載櫻校 瀏覽:580
現在什麼app可以賺錢 瀏覽:155
基礎梁鋼筋圖紙未標注加密區間距 瀏覽:469
通達信指標源碼公式半透明 瀏覽:956
開發什麼手機app好 瀏覽:319
csgo如何在游戲里進入完美伺服器 瀏覽:190
編程教育老師成長心態 瀏覽:257
音頻採集單片機 瀏覽:590
加密管的優點 瀏覽:280
dock基礎命令 瀏覽:345
java編程愛好者 瀏覽:723
做外包程序員怎麼樣 瀏覽:866
程序員技術門檻 瀏覽:474