c 下 socket 客戶端 程式設計

2021-05-27 02:49:33 字數 921 閱讀 8823

using system.io;

using system.net.sockets;

using system.net;

private void button4_click(object sender, eventargs e)

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

ipaddress serverip = ipaddress.parse("192.168.1.107");  //伺服器ip

try{

ipendpoint iep=new ipendpoint(serverip,9100);

s.connect(iep);            //連線伺服器,埠號用13

catch (exception ex)

{messagebox.show(ex.message);

try{

ns = new networkstream(s);           //例項化網路流

sr = new streamreader(ns);           //例項化流讀取物件

sw = new streamwriter(ns);           //例項化寫入流物件

sw.writeline(textbox1.text);          //將textbox1.text的資料寫入流

sw.flush();                    //清理緩衝區

listbox1.items.add(sr.readline());        //將從流中讀取的資料寫入lbinfo

catch (exception ex)

{messagebox.show(ex.message);          //捕獲異常

c 下 socket 客戶端 程式設計

using system.io using system.net.sockets using system.net private void button4 click object sender,eventargs e s new socket addressfamily.internetwork...

SOCKET客戶端程式設計

1.建立socket物件 socket建構函式有4個引數,第乙個是family,代表位址家族af net,af net6等,第二個是type,套接字型別sock stream 流套接字 和sock dgram 資料報套接字 import socket s socket.socket socket.a...

socket程式設計範本 客戶端

include include void main if lobyte wsadata.wversion 1 hibyte wsadata.wversion 1 socket sockclient socket af inet,sock stream,0 建立套接字 socket sockaddr ...