static void Main(string[] args) { RAS.RasManager rm = new RasManager(); rm.EntryName = "rwpppoe"; rm.Password = "******"; rm.UserName = "******"; int a = rm.Connect(); //Console.WriteLine("Return message = {0}", a); if (a == 0) { Console.WriteLine("连接成功,按任意键退出"); } else { Console.WriteLine("连接失败,错误代码{0},按任意键退出", a); } Console.ReadKey(); }
//private static bool hadSetDialParam = false; //是否已设置过apn参数,避免重复设置 public static bool CreateConnection(int retryTimes, string hostIP, int hospPort) { bool ret = false; if (retryTimes == 0) { retryTimes = 2; //默认连接两次 } try { if (!IsUse) { Log.Warn("已关闭GPRS模块,无需拨号"); return(true); } else { Log.Info("开始拨号..."); RasManager rsm = new RasManager(); if (rsm.isConnect() && (CheckConnection(hostIP, hospPort))) { Log.Warn("已经在线"); return(true); } else { if (GetInstance().UseAppDialParam) { if (!SetDialParam()) { return(false); } } rsm.UserName = ""; rsm.Password = ""; rsm.PhoneNumber = GetInstance().ApnDialNum; Log.Info("拨号号码:" + rsm.PhoneNumber); for (int i = 0; i < retryTimes; i++) { int rsmRet = rsm.Connect(); Log.Info("rsm Connect Return:" + rsmRet.ToString()); if (rsmRet == 0) { ret = true; break; } if (rsm.isConnect()) { ret = true; break; } } Log.Info("多次拨号完成 ret=" + ret.ToString()); } } } catch (Exception err) { Log.Error("[GPRS][CreateConnection]Error!\n", err); ret = false; } return(ret); }