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

熱點內容
解壓玩法視頻 瀏覽:463
蘋果xls如何設置加密 瀏覽:203
湖北廣電dns的伺服器地址是多少 瀏覽:527
php獲取原始數據 瀏覽:246
pic單片機如何編程 瀏覽:890
javabyte寫文件 瀏覽:321
java獲取類包名 瀏覽:890
ftp命令編碼格式 瀏覽:299
程序員那麼可愛陸離穿正裝 瀏覽:171
源碼的賬號密碼在哪個文件 瀏覽:441
如何在中國農業銀行app綁定銀行卡 瀏覽:994
shopnum1多用戶商城系統源碼 瀏覽:748
紅包廣告平台源碼 瀏覽:774
硬碟格式化時用的dos命令是 瀏覽:942
找人緩解壓力 瀏覽:940
iphone的pdf 瀏覽:353
90壓縮餅干怎麼吃 瀏覽:670
php教材下載 瀏覽:917
什麼解壓密碼最好 瀏覽:592
資料庫與伺服器如何連接 瀏覽:446