Android uses Ntrip protocol, socket connection gets access point, login mode

Source: Internet
Author: User

The previous time travel to solve a problem, is to get access points, as well as login mode. The problem with the mobile network differential setting in this process is to use the Ntrip protocol. This is a bit of a pit, is the server side is not according to the Protocol to the standard processing of these validation data. The first is a socket connection, the socket connection on the Send protocol. This agreement is ntrip to do.
Ntrip Agreement: Click

1. Use the backgroundYou can create a new APN setting by using the access point settings, Android system settings, and mobile networks, which are up to the phone card. Some special cards, dedicated network use need to self-set APN. The access point of our own mobile network is the default. such as:






2. Code Socket ConnectionThe required parameter is the IP address, the port is OK.
Socket connection class, and send data, receive data and so on.

Package Com.aualarm.util;import Java.io.bufferedinputstream;import Java.io.bufferedoutputstream;import Java.io.datainputstream;import Java.io.dataoutputstream;import Java.io.ioexception;import Java.net.inetsocketaddress;import Java.net.socket;import Java.net.socketaddress;import Android.os.Handler;import Android.os.message;import Android.util.log;public class Clientinfothread extends thread{socket Socket = null; Handler Handler;  String host = "10.10.100.254";                Default: TCP Server ports 20108int port = 8899; Default port 888boolean need_send_cmd = false;datainputstream dis = Null;dataoutputstream dos = null;public clientinfothread ( Handler Handler) {this.handler = Handler;} public void Set_host_port (String host,int port) {this.host = Host;this.port = port;}            public void Run () {try {byte readbuffer[] = new BYTE[64];      try {//socket = new socket (host,port);            Socket = new socket ();      SocketAddress socketaddress = new inetsocketaddress (host,port); Socket.coNnect (socketaddress,2000);    Socket.setsotimeout (2000);          Socket.settcpnodelay (TRUE);    dis = new DataInputStream (New Bufferedinputstream (Socket.getinputstream ()));        DOS = new DataOutputStream (New Bufferedoutputstream (Socket.getoutputstream ()));    Publicinfo.connected_server = true;        Message msg = new Message (); msg.what = 0x1236;msg.obj = Readbuffer;handler.sendmessage (msg); while (!      Thread.interrupted ()) {if (publicinfo.need_send_cmd) {publicinfo.need_send_cmd = false;      LOG.I ("Show", PublicInfo.buf.toString ());      Dos.write (publicinfo.buf, 0, publicinfo.buf_length);      Dos.flush ();  } int count = 0;   try {count = Dis.read (Readbuffer);   } catch (IOException e) {continue;    } if (count < 1) continue;    String line = null; line = new String (readbuffer, 0, Count);    Message MSG2 = new Message (); msg2.what = 0x1234;msg2.obj = Line;msg2.arg1 = Count;handler.sendmessage (MSG2); }}finally {if (Dos! = nulL) dos.close ();  if (dis! = null) dis.close ();  if (socket! = NULL) socket.close ();  Publicinfo.info_thread_exit = true;    Publicinfo.connected_server = false; }} catch (Exception e) {e.printstacktrace (); Message msg = new Message (); msg.what = 0x1235;msg.obj = E.getmessage (); Handler.sendmessage (msg);}}}
data structure class for sending
public class Publicinfo {public static byte buf[] = null;public static int buf_length;public static Boolean need_send_cmd; public static Boolean recv_thread_exit;public static Boolean info_thread_exit;public static Boolean Connected_server;}

This is the socket connection to start, generally have to open a thread to connect.

if (publicinfo.connected_server) {//is already connected to the server and needs to be disconnected after reconnecting      disconnect_server ();  }  Publicinfo.connected_server = false;  Client_info_thread = new Clientinfothread (netmessagehandle);  Client_info_thread.set_host_port ("10.10.100.254",          sharepreferenceutil.device_port);  Client_info_thread.start ();

The thread receives the data and processes the message mechanism on the interface.

Message Handler Object  handler Netmessagehandle = new Handler () {public      void Handlemessage (Message msg) {          ///If the message is 0X1234 is the data that is transferred from the thread          if (msg.what = = 0x1234) {              Show_result (msg.obj.toString (), MSG.ARG1), and//The data of the buffer is displayed to ui
   
    }          //If the message is 0x1234, it is the data transferred from the thread if          (msg.what = = 0x1235) {              toast.maketext (Getapplicationcontext (),                      GetString (r.string.mainnetclose) + msg.obj,                      toast.length_long). Show ();          if (msg.what = = 0x1236) {}}}              ;
   

3. Ntrip AgreementA, after the successful connection, get access Point Protocol
get/http/1.1  user-agent:ntrip netset_debug  Accept: */*  connection:close  authorization:basic Mde5mzownzew  

Netset_debug This is debug, here can carry parameters can be customized
Authorization:basic Mde5mzownzew This line of users is to verify that some servers are to take parameters, even if carrying the parameters USER:PSW composed by Base64 encoded.
When getting access points, some servers do not take this parameter to pass, this user name and password is not very much related to the wrong, but to have to carry. Not to carry is such a authorization:basicThe parsing code can refer to the code:

String strresult[] = Strdatastring.split ("STR;");  for (int i = 1; i < strresult.length; i++) {      streamdetails temdetails = new Streamdetails ();        Press ";" for the second time. Flag, intercept string      strfinallresult[] = Strresult[i].split (";");      Temdetails.strmountpoint = strfinallresult[0];      Add (temdetails);  }
B, Login modeThe first is to get access points, after success will give you a bunch of data, self-parsing, and then resolve to the access point, put to the head carry Get/rtcm31 http/1.1, where/RTCM31 is the access point
Get/rtcm31 http/1.1  user-agent:ntrip 54168078020418  Accept: */*  connection:close  Authorization : Basic dgvzddoyotc4mze=

Dgvzddoyotc4mze= is a BASIC64 code that can be viewed in this document. The parameter USER:PSW is composed of Base64 encoded.
Similar to the following code:


The user password is converted to BASE64 encoded          String userpassword = "Test" + ":" + "297831";  String Base64userpassword = "";  try {      Base64userpassword = Urldecoder.decode (base64.encodetostring (Userpassword.getbytes (), Base64.NO_WRAP), " UTF-8 ");  } catch (Unsupportedencodingexception e) {      //TODO auto-generated catch block      e.printstacktrace ();  }  


Login verification successfully returned
ICY OK
There are other documents to return to see this: Ntrip protocol: click

Android uses Ntrip protocol, socket connection gets access point, login mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.