title: How to send and receive SMS in java?
body: <p>I want my Java application to send and receive <strong>SMS</strong> without using any additional hardware devices and it must be free.</p>
  
  <p>I made my search but all i found is titles, i found somethings like <strong>SMSLib</strong> but at the other hand i didn't find tutorials or books to learn that.</p>
  
  <p>I also found that <strong>SMSLib</strong> code but didn't understand:</p>
  
  <p><strong>Send Message/SMS Code</strong></p>
  
  <pre><code>package SMSEngine;
  import org.smslib.*;
  class SendMessage
  {
  public static void sendMessage(String number, String message)
  { 
  CService srv = new CService("COM4",9600,"huawei","E220");
  try
  {
  srv.setSimPin("0000");
  srv.setSimPin2("0000");
  srv.setSmscNumber("");
  srv.connect();
  COutgoingMessage msg = new COutgoingMessage(number, message); 
  msg.setMessageEncoding(CMessage.MessageEncoding.Enc7Bit);
  msg.setStatusReport(true);
  msg.setValidityPeriod(8);
  srv.sendMessage(msg);
  srv.disconnect();
  }
  catch (Exception e)
  {
  e.printStackTrace();
  }
  System.exit(0);
  }
  }
  </code></pre>
  
  <p><strong>Read Message/SMS Codes</strong></p>
  
  <pre><code>package SMSEngine;
  import org.smslib.*;
  import java.util.*;
  class ReadMessages
  {
  static CService srv;
  public static LinkedList receiveMessage()
  {
  LinkedList msgList = new LinkedList();
  /*
  To Check COM port Go in following path in Windows7
  Control Panel\Hardware and Sound\Bluetooth and Local COM
  
  */
  srv = new CService("COM4",9600,"huawei","E220");//"COM1", 57600, "Nokia", ""
  try
  {
  srv.setSimPin("0000");
  srv.setSimPin2("0000");
  srv.connect();
  srv.readMessages(msgList, CIncomingMessage.MessageClass.Unread);
  srv.disconnect();
  return msgList;
  }
  catch (Exception e)
  {
  e.printStackTrace();
  }
  System.exit(0);
  return msgList;
  }
  }
  </code></pre>