使用 GPRS 的 WM6 插座

发布于 2024-11-30 09:59:13 字数 1702 浏览 0 评论 0原文

我正在 WM6 上的 NTRIP 客户端上写作。基本上,我通过首先发送配置来使用套接字从服务器获取数据。但我无法让它在同一设备上通过 GPRS 连接运行。

我发送此消息。

Get / HTTP/1.0
User-Agent: NTRIP client
Accept: */*
Connection: close

到这个服务器。

Hostname: mamba.gps.caltech.edu
Port: 2101

我通过执行此操作建立连接

string message = "GET / HTTP/1.0\r\nUser-Agent: NTRIP client\r\nAccept: */*\r\nConnection: close\r\n\r\n"
IPAddress ipAddress = Dns.GetHostEntry(hostname).AddressList[0];

_NTRIPCaster = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_NTRIPCaster.Connect(new IPEndPoint(ipAddress, Convert.ToInt32(port)));
_NTRIPCaster.Send(Encoding.ASCII.GetBytes(message));
for (int i = 0; i < 50; i++) //Wait for upto 5 seconds for a response
{
     Thread.Sleep(100);
     if (_NTRIPCaster.Available > 0)
     {
           Byte[] inBytes = new byte[_NTRIPCaster.Available];
           _NTRIPCaster.Receive(inBytes);
           sourceTable += Encoding.ASCII.GetString(inBytes, 0, inBytes.Length);
           //Check if all of the Source table has been recieved
           if (sourceTable.Contains("ENDSOURCETABLE")) 
           {
                 sourceTableRecieved = true;
                 break;
           }
      }
}

如果我有 Wi-Fi 连接,或者设备已对接至 PC 并且主动同步正在共享 PC 的互联网连接,则一切正常。

如果我切断 PC 上的互联网,并禁用 Wi-Fi,则无法将主机名解析为 IP 地址。甚至没有到达套接字连接。基本上它不使用设备中的调制解调器并使用 GPRS 连接。无论是否连接 GPRS,都会发生这种情况。

由于我使用的是 WM6,因此我查看了连接管理器 API - http://msdn。 microsoft.com/en-us/library/aa458120

但是在关注了其他一些帖子之后,我在 stackoverflow 和其他论坛上找到了它,但我无法让它工作。有谁知道如何建立 GPRS 连接并开始向服务器发送数据。

I am writing at NTRIP client on WM6. Basically I am getting data from a server using sockets by first sending a configuration. But I am unable to get it working over a GPRS connection on the same device.

I send this message.

Get / HTTP/1.0
User-Agent: NTRIP client
Accept: */*
Connection: close

To this server.

Hostname: mamba.gps.caltech.edu
Port: 2101

I make the connection by doing this

string message = "GET / HTTP/1.0\r\nUser-Agent: NTRIP client\r\nAccept: */*\r\nConnection: close\r\n\r\n"
IPAddress ipAddress = Dns.GetHostEntry(hostname).AddressList[0];

_NTRIPCaster = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_NTRIPCaster.Connect(new IPEndPoint(ipAddress, Convert.ToInt32(port)));
_NTRIPCaster.Send(Encoding.ASCII.GetBytes(message));
for (int i = 0; i < 50; i++) //Wait for upto 5 seconds for a response
{
     Thread.Sleep(100);
     if (_NTRIPCaster.Available > 0)
     {
           Byte[] inBytes = new byte[_NTRIPCaster.Available];
           _NTRIPCaster.Receive(inBytes);
           sourceTable += Encoding.ASCII.GetString(inBytes, 0, inBytes.Length);
           //Check if all of the Source table has been recieved
           if (sourceTable.Contains("ENDSOURCETABLE")) 
           {
                 sourceTableRecieved = true;
                 break;
           }
      }
}

This all works fine if I have a Wi-Fi connection, or the device is docked to a PC and active sync is sharing the PCs internet connection.

If I cut off the internet on the PC, and disable the Wi-Fi then its unable to resolve the hostname to an IP address. Doesn't even get to the socket connections. Basically it is not using the modem in the device and making use of a GPRS connection. This happens whether the GPRS is connected or not.

Since I am on WM6, I have looked at the connection manager API - http://msdn.microsoft.com/en-us/library/aa458120 .

But after following a few other posts I have been able to find on stackoverflow and other forums I have been unable to get it to work. Does anyone know how I can make a GPRS connection and start sending data to a server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩余の解释 2024-12-07 09:59:13

如果您使用 HttpRequest 等更高级别的网络对象,则 .NET Framework 会自动调用连接管理器 API。您使用低级套接字有什么原因吗?

If you use the higher level network objects like the HttpRequest then the connection manager API is automatically invoked by the .NET Framework. Is there a reason you are using low-level sockets?

混浊又暗下来 2024-12-07 09:59:13

经过大量实验后,我让它发挥作用。

使用OpenNetCF的SDF中的ConnectionManager

  ConnectionManager connectionManager = new ConnectionManager();
  connectionManager.Connect(false);
  Thread.Sleep(50); //Give it time to make a connection

接下来,我使用了TCP/IP连接方法。老实说,我不确定这与 TCP 协议的套接字有何不同,因为据我所知,TCPClient 对象有一个名为 Client 的属性,它本身就是一个套接字。下面删除了代码示例。

       using (NetworkStream ns = _client.GetStream())
       using (MemoryStream ms = new MemoryStream())
       {
           ns.Write(messageBytes, 0, messageBytes.Length);
           for (int i = 0; i < 50; i++)
           {
               Thread.Sleep(20);
               byte[] buffer = new byte[16 * 1024];
               int bytes;
               while ((bytes = ns.Read(buffer, 0, buffer.Length)) > 0)
               {
                   ms.Write(buffer, 0, bytes);
               }
               byte[] data = ms.ToArray();
               response += Encoding.ASCII.GetString(data, 0, data.Length);
           }

我现在正在按预期发送和接收数据。

After alot of experimenting I got it to work.

Used the ConnectionManager, in SDF from OpenNetCF

  ConnectionManager connectionManager = new ConnectionManager();
  connectionManager.Connect(false);
  Thread.Sleep(50); //Give it time to make a connection

Next, I used the TCP/IP method of connection. Honestly, I am not sure how this differs to sockets with a TCP protocol, as from what I can tell a TCPClient object, has a property called Client which itself is a socket. Stripped down sample of code below.

       using (NetworkStream ns = _client.GetStream())
       using (MemoryStream ms = new MemoryStream())
       {
           ns.Write(messageBytes, 0, messageBytes.Length);
           for (int i = 0; i < 50; i++)
           {
               Thread.Sleep(20);
               byte[] buffer = new byte[16 * 1024];
               int bytes;
               while ((bytes = ns.Read(buffer, 0, buffer.Length)) > 0)
               {
                   ms.Write(buffer, 0, bytes);
               }
               byte[] data = ms.ToArray();
               response += Encoding.ASCII.GetString(data, 0, data.Length);
           }

I am now getting data sent and received as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文