小白學習貼 C TCP伺服器

2021-08-03 16:50:43 字數 1001 閱讀 7419

剛入行3周,boss讓我寫個tcp伺服器+客戶端…

只是單純實現功能,等經驗豐富後會回頭來優化

使用者登入的時候是通過redis快取伺服器來判斷,現在還沒有接觸到和mysql互動.

如果有大牛經過,勞煩你指出不足

//主函式入口

iredisclient redis = redismanager.getclient();

listersocket = new socket(addressfamily.internetwork,sockettype.stream, protocoltype.tcp);

listersocket.bind(new ipendpoint(ipaddress.parse("127.0.0.1"), 6523));

listersocket.listen(4);

console.writeline("伺服器已啟動");

onloginquestevent += new logindel(onlogin);

while (true)

catch (system.exception e)

}///

/// 處理資料

//////

static

void recmsg(object socket)}}

else

}catch (socketexception se)}}

////// 效驗密碼

//////

///public

static

void

onlogin(socket socket, string str, ref

bool isquest)//改變使用者的isquest

;user.store(newuser);

}if (socket != null && str != null)

}if (isquest == true)}}

}}

}

C tcp伺服器端

伺服器端 include stdafx.h include winsock2.h pragma comment lib,ws2 32.lib include using namespace std int tmain int argc,char ar 建立套接字 sserver socket af ...

C TCP 伺服器客戶端Socket程式設計

server.cpp include include using namespace std include define buf size 64 pragma comment lib,ws2 32.lib int main 建立監聽的socket sserver socket af inet,so...

小白伺服器硬體知識

一台伺服器的重要組成部分為 cpu,記憶體,硬碟,主機板,電源等等 主機板 伺服器主機板分成 x58 1366 x79 2011 x99 2011 3 lga1567,lga3647 x58 多適用於比較舊的cpu x79 適用於xcon e3,e5系列的v1,v2 x99 適用於xcon e5系列...