——此文章摘自《ASPNET网络数据库开发实例精解》定价¥ 特价¥ 详细>>http://tracklinktechcn/?m_id=dangdang&a_id=A&l=&l_type= width= height= border= nosave> fileSteamClose(); //关闭发送数据的Socket sendsocketShutdown(SocketShutdownSend); sendsocketClose(); } 单击页面MySocketaspx中的【接收数据】按钮触发事件ReceiveBtn_Click (object sender SystemEventArgs e)该事件调用函数SendReceiveData()接收从函数SocketSend()发送的数据函数SendReceiveData()首先创建用来接收数据的Socket对象并设计接收数据的IP地址和端口最后把接收的数据写入文件并保存函数SendReceiveData()和事件 ReceiveBtn_Click(object sender System EventArgs e)的程序代码如下 private void ReceiveBtn_Click(object sender SystemEventArgs e) { //接收数据 SendReceiveData(); } private void SendReceiveData() { //创建接收数据的Socket Socket receiveSocket = new Socket(AddressFamilyInterNetwork SocketTypeStreamProtocolTypeTcp); //设置接收数据的地址 IPEndPoint hostPoint = new IPEndPoint(IPAddressParse()); //设置端口 receiveSocketBind(hostPoint); //监听 receiveSocketListen(); //设置接收数据缓沖区的大小 Byte[] recData = new Byte[]; Socket hostSocket = receiveSocketAccept(); //接收数据 hostSocketReceive(recData); if(hostSocketReceive(recData) > ) { //显示接收数据的信息 LabelDataText = 网页在 + DateTimeNowToString() + 接收的数据大小为 + hostSocketReceive(recData)ToString(); } //创建一个新文件保存接收的数据 right>[http://developcsaicn/dotnet_ASP/htm>] [http://developcsaicn/dotnet_ASP/htm>] [] [http://developcsaicn/dotnet_ASP/htm>] |