伺服器端的**
using客戶端的**system;
using
system.collections.generic;
using
system.componentmodel;
using
system.data;
using
system.drawing;
using
system.linq;
using
system.text;
using
system.windows.forms;
using
system.net;
using
system.net.sockets;
using
system.threading;
using
system.io;
namespace
private
void tbportnum_keypress(object
sender, keypresseventargs e)
if (tbportnum.text != ""
)
}//private void bgworker_dowork(object sender, doworkeventargs e)
//
//獲取本機的ip
//獲取本機的ip
public
boolean socketisconnected(socket soc)
catch
return
isconnected;
}public
string
getlocalip()
socket sock;
//定義乙個socket類的物件 (預設為protected)
thread th; //
定義乙個thread類的物件
socket newsock;
//backgroundworker bgw = new backgroundworker();
private
void beginlisten() //
socket監聽函式, 等下作為建立新執行緒的引數
while (true
)
catch}}
catch (socketexception se) //
捕捉異常,}}
private
void bgworker_doworkclintip(object
sender, doworkeventargs e)
private
void addclintippage(object
o, system.eventargs e)
private
void bgworker_dowork(object
sender, doworkeventargs e)
private
void showgetbyte(object
o, system.eventargs e)
private
void btcreserver_click(object
sender, eventargs e)
catch (socketexception se) //
處理異常
catch (argumentnullexception ae) //
引數為空異常
}else
}private
void btsendmsg_click(object
sender, eventargs e)
catch
(argumentnullexception ae)
catch
(socketexception se)
}tbsendmsg.text = ""
; }
private
void tbportnum_textchanged(object
sender, eventargs e)
private
void tbrecmsg_textchanged(object
sender, eventargs e)
private
void button1_click(object
sender, eventargs e)
private
void form1_load(object
sender, eventargs e)}}
usingsystem;
using
system.collections.generic;
using
system.componentmodel;
using
system.data;
using
system.drawing;
using
system.linq;
using
system.text;
using
system.windows.forms;
using
system.net.sockets;
using
system.threading;
using
system.net;
namespace
public
boolean socketisconnected(socket soc)
catch
return
isconnected;
}private socket sock; //
定義乙個socket類的物件 (預設為protected)
thread th; //
定義乙個thread類的物件
//socket newsock;
private
void beginlisten() //
socket監聽函式, 等下作為建立新執行緒的引數
//else
//do
while(true
);
}private
void bgworker_dowork(object
sender, doworkeventargs e)
private
void showgetbyte(object
o, system.eventargs e)
//當點選連線伺服器的時候
private
void btconnectserver_click(object
sender, eventargs e)
catch (socketexception se) //
處理異常
catch (argumentnullexception ae) //
引數為空異常
}else
}private
void btsend_click(object
sender, eventargs e)
catch
(argumentnullexception ae)
catch
(socketexception se)
}textsend.text = ""
; }
private
void textip_textchanged(object
sender, eventargs e)
private
void button1_click(object
sender, eventargs e)}}
客戶端通過WebService實現和服務端書互動
webservice作為 一種服務,它不需要客戶端提供額外的軟體支援,只要客戶端支援 協議和xml 這樣兩個特性就可以了。對 webservice 自身來講,它本身就是一種自我描述型的設計,所以服務端和客戶端可以通過它來響應和處理請求的內容及格式。xml是一種平台無關 語言無關的文件結構,因此 we...
WCF客戶端和服務的實現
wcf客戶端和服務 伺服器端 定義和實現服務契約 為服務型別構建servicehost例項,暴露endpoints 開啟通訊通道 客戶端 需要服務契約的乙個副本和關於endpoints的資訊 為特定的endpoint構建通訊通道並且呼叫操作 客戶端的客戶程序中,有乙個 該 主要功能是完成客戶程序和主...
socket(C )客戶端和服務端
define winsock deprecated no warnings include include define port 5150 define msgsize 1024 pragma comment lib,ws2 32.lib void main system pause includ...