/// <summary> /// 发送测试Socket请求 /// </summary> private async void SendSocketRequest() { SocketRequest request = new SocketRequest(); IPAddress address = null; try//检测IP是否合法 { address = IPAddress.Parse(model.SiteAddress); } catch { await new MessageDialog("It's a wrong Address").ShowAsync(); return; } int port = 0; if (!int.TryParse(model.Port, out port))//检测端口号是否为数字 { await new MessageDialog("the port is wrong").ShowAsync(); } IPEndPoint iPEndPoint = new IPEndPoint(address, port); request.TargetEndPoint = iPEndPoint; await request.MakeRequest(); await new MessageDialog(request.ProtocolInfo).ShowAsync();//显示返回信息 }
/// <summary> /// 使用Socket 与服务器建立连接 /// </summary> /// <returns></returns> public async Task <LogModel> ConnectToServerWithSocket(SiteModel site, SocketRequest request) { IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(site.Site_address), site.Server_port); if (null != endPoint.Address && !("".Equals(endPoint.Address))) { request.TargetEndPoint = endPoint; #region 初始化log LogModel log = new LogModel { Site_id = site.Id, Create_time = DateTime.Now }; #endregion // 开始请求 bool result = await request.MakeRequest(); // 处理请求记录 CreateLogWithRequestServerResult(log, request); // 补充额外添加的判断 log.Log_record = request.ProtocolInfo; // 更新站点信息 UpdateSiteStatus(site, log); return(log); } return(null); }
/// <summary> /// 发送测试Socket请求 /// </summary> private async void SendSocketRequest() { SocketRequest request = new SocketRequest(); IPAddress address = null; try { Task<IPAddress> getAddress = util.GetIPAddressAsync(model.SiteAddress);//获取IP地址 await getAddress; address = getAddress.Result; } catch//域名解析失败 { await new MessageDialog("The domain name is not exist ").ShowAsync(); return; } if (address == null)//如果IPAddress为null说明域名错误 { await new MessageDialog("The domain name is wrong ").ShowAsync(); return; } int port = 0; if (!int.TryParse(model.Port, out port))//检测端口号是否为数字 { await new MessageDialog("The port is wrong").ShowAsync(); } IPEndPoint iPEndPoint = new IPEndPoint(address, port); request.TargetEndPoint = iPEndPoint; await request.MakeRequest(); await new MessageDialog(request.ProtocolInfo).ShowAsync();//显示返回信息 }
/// <summary> /// 使用Socket 与服务器建立连接 创建者: xb 创建时间:2018/05/10 /// </summary> /// <returns></returns> public async Task <LogModel> ConnectToServerWithSocket(SiteModel site, SocketRequest request) { #region 初始化log LogModel log = new LogModel { Site_id = site.Id, Create_Time = DateTime.Now }; #endregion IPAddress ip = await GetIPAddressAsync(site.Site_address); // IP 不合法 if (null == ip) { log.TimeCost = 7500; log.Status_code = "1001"; log.Is_error = true; log.Log_Record = "Address Format Is Invalid!"; } else { IPEndPoint endPoint = new IPEndPoint(ip, site.Server_port); request.TargetEndPoint = endPoint; // 开始请求 bool result = await request.MakeRequest(); // 处理请求记录 CreateLogWithRequestServerResult(log, request); // 补充额外添加的判断 log.Log_Record = request.ProtocolInfo; // 更新站点信息 UpdateSiteStatus(site, log); } return(log); }