static void Main(string[] args) { Console.Write("Input server name : "); string hostName = Console.ReadLine(); string ip = ""; string portStr = ConfigurationManager.AppSettings["ServerPort"]; int port = 0; if (!string.IsNullOrEmpty(portStr)) { port = Convert.ToInt32(portStr); } foreach (IPAddress ipaddress in Dns.GetHostEntry(hostName).AddressList) { if (ipaddress.AddressFamily == AddressFamily.InterNetwork) { ip = ipaddress.ToString(); } break; } if (ip != "") { client = new GSMClient.Client(ip, port); } else { client = new GSMClient.Client(hostName, port); } client.Open(); Console.WriteLine("Connection established {0}", client.GetClient().Client.RemoteEndPoint); Send(client.GetClient()); Console.ReadKey(); }
private void FormMain_Load(object sender, EventArgs e) { gsmClient = new GSMClient.Client(Properties.Settings.Default.SMSGatewayIP, Properties.Settings.Default.SMSGatewayPort); gsmClient.Open(); command = new CommandCollection(); Thread threadRead = new Thread(new ParameterizedThreadStart(Read)); threadRead.Start(gsmClient.GetTcpClient()); }
private void FormMain_Load(object sender, EventArgs e) { gsmClient = new GSMClient.Client(Properties.Settings.Default.SMSGatewayIP, Properties.Settings.Default.SMSGatewayPort); gsmClient.Open(); command = new CommandCollection(); Thread threadRead = new Thread(new ParameterizedThreadStart(Read)); threadRead.Start(gsmClient.GetTcpClient()); }
//public void OnDataSent(string data) //{ //} public void OnDataReceived(string data) { List <BaseResult <SMSReadResult> > list = JsonHelper.JsonDeserialize <List <BaseResult <SMSReadResult> > >(data); if (list.Count > 0) { foreach (BaseResult <SMSReadResult> read in list) { if (read.Response.TypeName.Contains("SMSRead")) { if (keywords.Any()) { foreach (QuizModel keyword in keywords) { Match match = new Regex(@"(.*[a-zA-Z]) (.*[a-zA-Z])").Match(keyword.Keyword); if (match.Success) { if (read.Response.Message.ToLower().Contains(match.Groups[1].Value.ToLower())) { string[] arg = read.Response.Message.ToLower().Split(new string[] { match.Groups[1].Value.ToLower() }, StringSplitOptions.RemoveEmptyEntries); using (IQuery con = new DapperDbContext(DatabaseConst.SMSGateway)) { List <Answer> result = con.Query <Answer>(keyword.Response, new { KeyID = arg[0].Trim() }); if (result.Any()) { smsSender = new GSMClient.Client(ipStr, Convert.ToInt32(portStr)); smsSender.Open(); smsSender.Send(string.Format(GSMClient.Command.CommandCollection.SMSSend, read.Response.From, result.SingleOrDefault().Description)); smsSender.Close(); } } break; } } } } } } } }
//public void OnDataSent(string data) //{ //} public void OnDataReceived(string data) { List<BaseResult<SMSReadResult>> list = JsonHelper.JsonDeserialize<List<BaseResult<SMSReadResult>>>(data); if (list.Count > 0) { foreach (BaseResult<SMSReadResult> read in list) { if (read.Response.TypeName.Contains("SMSRead")) { if (keywords.Any()) { foreach (QuizModel keyword in keywords) { Match match = new Regex(@"(.*[a-zA-Z]) (.*[a-zA-Z])").Match(keyword.Keyword); if (match.Success) { if (read.Response.Message.ToLower().Contains(match.Groups[1].Value.ToLower())) { string[] arg = read.Response.Message.ToLower().Split(new string[] { match.Groups[1].Value.ToLower() }, StringSplitOptions.RemoveEmptyEntries); using (IQuery con = new DapperDbContext(DatabaseConst.SMSGateway)) { List<Answer> result = con.Query<Answer>(keyword.Response, new { KeyID = arg[0].Trim() }); if (result.Any()) { smsSender = new GSMClient.Client(ipStr, Convert.ToInt32(portStr)); smsSender.Open(); smsSender.Send(string.Format(GSMClient.Command.CommandCollection.SMSSend, read.Response.From, result.SingleOrDefault().Description)); smsSender.Close(); } } break; } } } } } } } }