C# .NET - Connect GPRS - Asked By rohan patel on 07-Jan-11 04:38 AM

i want code for connect GPRS using .net application
Vivek Jagga replied to rohan patel on 07-Jan-11 04:49 AM
Hi Rohan

I found 2 articles, check these

http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesvbcs/thread/39c50907-23f4-43d2-bf74-0a28d00748e8

http://www.treaple.com/bbs/thread-10-1-1.html

Reena Jain replied to rohan patel on 07-Jan-11 05:16 AM
hi,
check this link 
http://www.opennetcf.org/.

There is a library and with it, you can command the GPRS connection.

The code looks like to:

ConnectionManager connMgr = new ConnectionManager(); // open connection manager
 
public void connectGPRS()
 
{
 
DestinationInfoCollection DIC = connMgr.EnumDestinations(); // look the different types of connection
 
long startTime;
 
try
 
{
 
foreach (DestinationInfo di in DIC)
 
{
 
if (di.description == "Internet") // for the connection "Internet" or what you want (it can be "The Internet), it depends on your smartphone
 
{
 
connMgr.Connect(di.guid, true, ConnectionMode.Asynchronous); // try to connect
 
}

If GPRS connection is available and just want to enable from your application, you can simply open a site from your code so that GPRS connections will be established.

Here is the code:

 
public static bool IsWebAccessible() // Call this class as follows: bool bResponse = Net.IsWebAccessible();
  {
   HttpWebRequest hwrRequest;
   HttpWebResponse hwrResponse;
 
   string strUrl = @"http://www.bing.com/";
   bool bConnected = false;
 
   try
   {
  hwrRequest = (HttpWebRequest)WebRequest.Create(strUrl);
  hwrResponse = (HttpWebResponse)hwrRequest.GetResponse();
 
  if (hwrResponse.StatusCode == HttpStatusCode.OK)
  {
   bConnected = true;
  }
   }
   catch (WebException we)
   {
  bConnected = false;
   }
   catch (Exception ex)
   {
  bConnected = false;
   }
   finally
   {
  hwrRequest = null;
  hwrResponse = null;
   }
 
   return bConnected;
  }
hope this will help you
rohan patel replied to Reena Jain on 15-Feb-11 04:37 AM
thanks 


http://patelrohan.blogspot.com/
rohan patel replied to Vivek Jagga on 15-Feb-11 04:38 AM
thankss



http://patelrohan.blogspot.com/