uwp - Windows iot core 发送数据到远程服务器 52.139.250.253 费用网络
问题描述
我编写了一个程序来收集数据并通过 4g 路由器将其传输到我的服务器。但是我发现windows IoT core从服务器52.139.250.253发送和接收数据,它需要很多网络,我搜索了很多,找不到有用的信息,我不知道发生了什么,我该如何禁用它?
这是我的代码,很简单
public class TcpConnection:IConnection
{
Socket _TcpClient;
IPEndPoint _ServerIp;
string _IpOrUrl = string.Empty;
int _PortNO;
Boolean IsRecieve { get; set; } = false;
private event Action<byte[]> DataRecieved = null;
private int _TcpTimeout { set; get; } = 5000;
public TcpConnection(string ipOrUrl, int portNO)
{
_ServerIp = new IPEndPoint(IPAddress.Parse(ipOrUrl), portNO);
_TcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_TcpClient.SendTimeout = this._TcpTimeout;//等待测试
this._IpOrUrl = ipOrUrl;
this._PortNO = portNO;
this.ConnectAsync();
}
public async void ConnectAsync()
{
try
{
if (!_TcpClient.Connected)
{
await this._TcpClient.ConnectAsync(_ServerIp);
AsynRecive();
}
}
catch { }
}
private void AsynRecive()
{
byte[] data = new byte[2048];
_TcpClient.BeginReceive(data, 0, data.Length, SocketFlags.None, asyncResult =>
{
try
{
int length = this._TcpClient.EndReceive(asyncResult);
if (length > 0)
{
byte[] bytesBack = data.Take(length).ToArray();
try
{
DataRecieved.Invoke(bytesBack);
}
catch (Exception Ex)
{
LogHelper.Log(Ex.Message.ToString(), LogLevel.Debug);
}
}
AsynRecive();
}
catch (Exception)
{
}
}, null);
}
public Boolean Send(byte[] data)
{
try
{
if (!this.IsConnect())
{
if (this.Reset())
{
this._TcpClient.Send(data);
}
}
else
{
this._TcpClient.Send(data);
}
return true;
}
catch { return false; }
}
public void Close()
{
this._TcpClient.Close();
}
public void Connect()
{
try
{
if (!_TcpClient.Connected)
{
this._TcpClient.Connect(_ServerIp);
AsynRecive();
}
}
catch(Exception Ex)
{ }
}
public bool IsConnect()
{
return _TcpClient.Connected;
}
public void AddRecieveHandle(Action<Byte[]> dataEvent)
{
this.DataRecieved -= dataEvent;
this.DataRecieved += dataEvent;
//throw new NotImplementedException();
}
public Boolean Reset()
{
try
{
_TcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_TcpClient.SendTimeout = this._TcpTimeout;
this.Connect();
return true;
}
catch {
return false;
}
}
public Task<bool> SendAsync(byte[] data)
{
return Task.FromResult(true);
}
}
解决方案
在连接初始化之前,您是否注意到转储中的 DNS 查找。看看这是否用于将域解析为该 IP 地址。如果是这样,它看起来与 WNS(Windows 推送通知服务)有关:https ://msdn.microsoft.com/de-de/windows/desktop/mt187203 。
推荐阅读
- java - Double.parseDouble 丢失小数位
- javascript - jQuery 表单验证在 JSP 中不起作用
- c++ - CLion 在远程计算机上找不到 C/C++ 标准库
- react-native - 如何在 React Native WebView 中加载视图之前在 WebView 本地存储中设置值
- dart - 如何从推送通知重定向到颤动的页面
- python - 为什么这段代码不输出获胜者变量?
- xml - 我无法在 python 中解析多个 xml 文件
- java - 将spring boot从2.1.4更新到2.1.5后java主类出现问题
- swift - 条件语句似乎无法正常运行
- google-sheets - 查找最近的时间戳以记录和绘制事件图表