freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

綜合實習(xí)課程設(shè)計說明書基于cs模式的tcp即時通信系統(tǒng)(編輯修改稿)

2025-07-16 04:18 本頁面
 

【文章內(nèi)容簡介】 public string IP。 public string status。 public string fg。//好友分組 }},我們則定義了FriendStruct的數(shù)組。在C中使用DATAREADER語句可以逐句讀取數(shù)據(jù)庫查詢的結(jié)果,再依次將結(jié)果賦值FriendStruct數(shù)組元素,就得到了便于發(fā)送和讀取的存放好友信息的數(shù)組。賦值代碼如下: while (()) //getf即是以上的數(shù)據(jù)庫查詢的datareader語句 { ff[i].account=getf[UserAccount].ToString()。 ff[i].IP = getf[UserIP].ToString()。 ff[i].nickname = getf[UserNickname].ToString()。 ff[i].status = getf[UserOnline].ToString()。 ff[i].fg = getf[FriendGroup].ToString()。 i++。 } ()。實現(xiàn)一個快捷簡單的數(shù)據(jù)庫連接的相關(guān)代碼是非常有必要的。實現(xiàn)的途徑也多種多樣,鑒于安全性和復(fù)雜性的需求不同,實現(xiàn)方法有簡有繁。本設(shè)計使用了一個簡單的類()實現(xiàn)了簡單快捷的數(shù)據(jù)庫連接和讀取。主要代碼如下: public static SqlConnection connStr = new SqlConnection(Server=D96B85DD938A465.。uid=sa。pwd=change。database=TCPDB)。 public static SqlDataReader SqlReader(string sql, SqlConnection connstr) { SqlDataReader sqldr = null。 SqlCommand cmd = new SqlCommand(sql, connstr)。 if (() == Closed) ()。 try { sqldr = ()。 } catch (Exception e) { if (e != null) sqldr = null。 } return sqldr。 } //數(shù)據(jù)庫操作連接 public static string SqlCmd(string sql, SqlConnection connstr) { string errorstr = null。 SqlCommand sqlcmd = new SqlCommand(sql, connstr)。 if (() == Open) ()。 ()。 try { ()。 } catch (Exception e) { if (e != null) errorstr = ()。 } ()。 return errorstr。 },主程序可以更方便地實現(xiàn)數(shù)據(jù)庫連接操作,對數(shù)據(jù)庫進(jìn)行讀寫和更新,在此不再詳述。這里顯示傳入的原始信息服務(wù)器端的界面設(shè)計是基于便于測試的目的而實現(xiàn)的。如下圖:這里顯示已連入的連接圖4 服務(wù)器端界面基于同步套接字的網(wǎng)絡(luò)監(jiān)聽器對服務(wù)器來說并不是最好的解決方案,但是仍然可行并且實現(xiàn)簡單。主要代碼如下:開啟監(jiān)聽端口: public void Serve() { int port = 8888。 ServerIPEP = new IPEndPoint(, port)。 s = new Socket(, , )。 ((EndPoint)ServerIPEP)。 (10)。 alSock = new ArrayList()。以下代碼讀取連入的連接,依次將連接加入可變長數(shù)組alsock,并且讀取傳入的信息,進(jìn)行反串行化: while (true) { try { uc = ()。 (uc)。 ((uc))。 byte[] data = new byte[2048]。 int rect = (data)。 byte[] chat = new byte[rect]。 (data, 0, chat, 0, rect)。 UMessage umessage = (UMessage)(new MemoryStream(chat))。 int info = 。對反串行化后的信息進(jìn)行處理,通過info參數(shù)辨認(rèn)客戶端行為(注冊或者登錄),對注冊的信息進(jìn)行數(shù)據(jù)庫查詢,注冊信息可插入,則將用戶信息插入數(shù)據(jù)庫,否則返回客戶端“注冊出錯”的信息: region 處理用戶注冊信息 if (info==0)//分辨出用戶發(fā)送的是注冊信息 { string Accounts = 。 SqlDataReader usdr = (select * from TCP_UserInfo where UserAccount=39。 + Accounts + 39。, )。 if (usdr != null) { if (()) { region 此處寫入返回注冊失敗的代碼 Socket sc = (Socket)alSock[(uc, 0)]。 (chat)。 endregion } else { region 此處寫入插入數(shù)據(jù)庫用戶注冊信息的代碼 Stream ms = new MemoryStream()。 Socket sc = (Socket)alSock[(uc, 0)]。 if ((insert into TCP_UserInfo (UserAccount,UserNickname,UserEmail,JoinDate,UserIP,UserPassword) values(39。 + + 39。,39。 + + 39。,39。 + + 39。,39。 + () + 39。,39。 + ((IPEndPoint)).() + 39。,39。 + + 39。), ) == null) { = 1。 (ms, umessage)。 byte[] d = new byte[]。 (0, )。 (d, 0, )。 (d)。 } else { = 2。 (ms, umessage)。 byte[] d = new byte[]。 (0, )。 (
點擊復(fù)制文檔內(nèi)容
外語相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1