title: Communicating a GPS/GPRS/GSM tracker with the server
body: <p>I am developing a vehicle tracking system which uses GPS/GPRS/GSM. The tracking device I am currently using is GV100, a GPS/GPRS/GSM tracker from Quectel ([www.quectel.com][1].) 
  I am not able to establish connection between the device and the backend server. My question particularly is:</p>
  
  <ol>
  <li>How do I send commands (AT Commands) to the device from the server? </li>
  <li>How do I accept the response (reports and acknowledgement messages) from the device to save it in the database?</li>
  </ol>
  
  <p>I sent command to the device with the MGV100 Manage Tool (Software provided by Quectel) via serial port. And I got acknowledgement SMS message on GSM enabled mobile telephone. Now, I want to send message from the server and accept reply on the server (not by SMS). I don’t know how to send command and receive the reply. I have no previous experience in developing such systems.</p>
  
  <p>It would be great if I can get a sample code and setup procedures if it requires.
  Where can I get a relevant tutorial for the case I mentioned?</p>
  
  <hr>
  
  <p>Thanks jhonkola</p>
  
  <hr>
  
  <p>To understand how server receives and send data to the device, I decided to first implement the communication between the client (currently my PC) and server. Though my ultimate goal is communicating with the device, currently I am trying to establish connection from my PC to the server. If I succeed in this, I will strive to communicate to server from the device which needs IP address and port number of server to send and receive data.<br>
  This is my assumption how to do it:    </p>
  
  <ul>
  <li>I can open a port on the server from .cs code so as to communicate
  using TCP/UDP. </li>
  <li>Client then can send and receive data via this
  port. </li>
  <li><p>I can save the data sent from the client on server's file
  system and review it any time. (Am not storing the data in relational database because I don't want to bother about database issues now.)
  This is how I tried to implement:<br>
  Server a C# Web Application:<br>
  When a button is clicked it opens a port and listens to client   </p>
  
  <pre><code>protected void btnConnect_Click(object sender, EventArgs e)
  {
      try
      {
          continueListening = true;
          while (continueListening)
          {
              int port=Int32.Parse(txtPort.Text);
              lblOutput.Text = "Port is now " + port +". Waiting for connection";
              TcpListener myList = new TcpListener(IPAddress.Parse(txtIpAddress.Text), port);
              myList.Start();
              Socket s = myList.AcceptSocket();
              lblOutput.Text="Connection accepted from " + s.RemoteEndPoint;
  
              byte[] b = new byte[100];
              int k = s.Receive(b);
              lblOutput.Text = ("Recieved...");
              String obtainedText = "";
              for (int i = 0; i &lt; k; i++)
              {
                  obtainedText = obtainedText + "  " + (Convert.ToChar(b[i]));
              }
              writeToTextFile("C:/Users/MekAtIbex/Desktop/TESTED/RECIEVED.txt", obtainedText);
              lblOutput.Text = obtainedText;
              ASCIIEncoding asen = new ASCIIEncoding();
              lblOutput.Text = lblOutput.Text +"  "+ ("The string was recieved by the server.");
              lblOutput.Text = lblOutput.Text +"  "+ ("\r\nSent Acknowledgement");
          } 
  </code></pre></li>
  </ul>
  
  <p>Client: C# Windows application</p>
  
  <pre><code>        private void btnSend_Click(object sender, EventArgs e)
          {
              try
              {
                  TcpClient tcpClient = new TcpClient();
                  int port=Int32.Parse(txtPort.Text.Trim());
  
                  tcpClient.Connect(txtIpAddress.Text, port);
                  lblStatus.Text = ("Connected");
                  Stream stm = tcpClient.GetStream();
                  ASCIIEncoding asen = new ASCIIEncoding();
                  byte[] bytesToSend = asen.GetBytes(txtData.Text);
                  lblStatus.Text = ("Transmitting.....");
  
                  stm.Write(bytesToSend, 0, bytesToSend.Length);
  
                  byte[] bb = new byte[100];
                  int k = stm.Read(bb, 0, 100);
  
                  for (int i = 0; i &lt; k; i++)
                  {
                      txtaResponse.Text = txtaResponse.Text + "\n" + "Res... " + new DateTime() + " " + Convert.ToChar(bb[i]);
                      Console.Write(Convert.ToChar(bb[i]));
                  }
                  tcpClient.Close();
              }
  
              catch (Exception ex)
              {
                  lblStatus.Text = ("Connected");
                  txtaRequest.Text = txtaRequest.Text + "\n" + "Err... " + new DateTime() + " " + ex.StackTrace;
              }
          }
  </code></pre>
  
  <p>My current questions are:</p>
  
  <ol>
  <li>Is my assumption correct? If not how should I do it?</li>
  <li>I have tried to save it using the above code but I didn't got the file. </li>
  <li>What is the advantage and disadvantage of using UDP in comparison TCP for tracking applications? 
  I have browsed well, but I couldn't find a place for a good start. And, as I have no experience in such applications, I couldn't debug my application.</li>
  </ol>