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

熱點內容
壓縮空氣管道流量計 瀏覽:562
ug編程高級教程 瀏覽:175
什麼叫做伺服器已滿 瀏覽:35
暑假哪有教演算法的 瀏覽:134
密碼學的根基是加密 瀏覽:660
stata方差檢驗命令 瀏覽:335
解壓後文件夾里的內容丟失 瀏覽:713
解壓無敵視頻 瀏覽:688
什麼是伺服器辨認不了 瀏覽:129
java如何調用類方法 瀏覽:483
管理孩子的app叫什麼 瀏覽:546
壓縮活動軌跡 瀏覽:674
6米梁加密筋 瀏覽:79
怎麼學好ps如何學好編程 瀏覽:301
c編譯器廠商 瀏覽:114
簡述編譯程序以及解釋程序 瀏覽:4
linux升級kernel 瀏覽:176
入侵伺服器挖礦是什麼罪 瀏覽:47
房屋解壓資料丟了怎麼辦 瀏覽:810
java文件行讀寫 瀏覽:544