第1页共10页编号:时间:2021年x月x日书山有路勤为径,学海无涯苦作舟页码:第1页共10页socket通信例子publicvoidsend(){while(true){stringsql="selecttop100*fromsend";SqlDataReaderdatareader=sqlserver
ExecuteSqlDataReader(sql);if(datareader
HasRows)//有记录才进行网关联接{stringshow;stringhost;//intport=Convert
ToInt16("8801");//host=Dns
GetHostName();//host="192
110";sockettemp=newsocket();Socketsend=temp
connectSocket(this
remote_ip,this
remote_port);if(send==null){this
send_listbox("打开远程SMG失败");}else{this
send_listbox("打开远程SMG成功");byte[]bind_content=sgip_test
bind(count);count_step();byte[]receive=newbyte[256];byteflag;send
Send(bind_content,bind_content
Length,0);//bindsend
Receive(receive,29,0);//bind_resp读取29位flag=sgip_test
bind_resp_result(receive);if(flag==0)this
send_listbox("成功联接到网关");elsethis
send_listbox("联接网关失败");while(datare