This is a discussion on socket programming within the VB.NET Programming forums, part of the Software Development category; Hi I'm new in pocket pc programming. i m developing chatting client in ppc. I'm confusing to start ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#11
| |||
| |||
| Hi I'm new in pocket pc programming. i m developing chatting client in ppc. I'm confusing to start my application. How to connect socket connection? I'm not a well known in socket programming... Could anybody pls help... ![]() |
|
#12
| |||
| |||
| Hey Mramesh! You want to connect socket programming in Compact Framework. right? So you should have to know about TcpClient Class. For more see the msdn link.... ![]()
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#13
| |||
| |||
| Establish a GPRS connection with TcpClient NETCF's HttpWebRequest automatically sets up a GPRS connection for web requests/web services when a wired/wi-fi connection is not available. Therefore, when you do a web request or consume a web service, developers do not need special coding to handle the GPRS connection case. This does not apply to lower level socket classes like TcpClient and UdpClient. With these classes, you would need to use the Connection Manager APIs to establish/release the connections. To allow users to more easily setup/release a GPRS connection, I have written a managed representation of the connection manager APIs that we need when we establish a GPRS connection with TcpClient: Code: public class GPRSConnection
{
const int S_OK = 0;
const uint CONNMGR_PARAM_GUIDDESTNET = 0x1;
const uint CONNMGR_FLAG_PROXY_HTTP = 0x1;
const uint CONNMGR_PRIORITY_USERINTERACTIVE = 0x08000;
const uint INFINITE = 0xffffffff;
const uint CONNMGR_STATUS_CONNECTED = 0x10;
static Hashtable ht = new Hashtable();
static GPRSConnection()
{
ManualResetEvent mre = new ManualResetEvent(false);
mre.Handle = ConnMgrApiReadyEvent();
mre.WaitOne();
CloseHandle(mre.Handle);
}
~GPRSConnection()
{
ReleaseAll();
}
public static bool Setup(Uri url)
{
return Setup(url.ToString());
}
public static bool Setup(string urlStr)
{
ConnectionInfo ci = new ConnectionInfo();
IntPtr phConnection = IntPtr.Zero;
uint status = 0;
if (ht[urlStr] != null)
return true;
if (ConnMgrMapURL(urlStr, ref ci.guidDestNet, IntPtr.Zero) != S_OK)
return false;
ci.cbSize = (uint) Marshal.SizeOf(ci);
ci.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ci.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
ci.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ci.bExclusive = 0;
ci.bDisabled = 0;
ci.hWnd = IntPtr.Zero;
ci.uMsg = 0;
ci.lParam = 0;
if (ConnMgrEstablishConnectionSync(ref ci, ref phConnection, INFINITE, ref status) != S_OK &&
status != CONNMGR_STATUS_CONNECTED)
return false;
ht[urlStr] = phConnection;
return true;
}
public static bool Release(Uri url)
{
return Release(url.ToString());
}
public static bool Release(string urlStr)
{
return Release(urlStr, true);
}
private static bool Release(string urlStr, bool removeNode)
{
bool res = true;
IntPtr ph = IntPtr.Zero;
if (ht[urlStr] == null)
return true;
ph = (IntPtr)ht[urlStr];
if (ConnMgrReleaseConnection(ph, 1) != S_OK)
res = false;
CloseHandle(ph);
if (removeNode)
ht.Remove(urlStr);
return res;
}
public static void ReleaseAll()
{
foreach(DictionaryEntry de in ht)
{
Release((string)de.Key, false);
}
ht.Clear();
}
[StructLayout(LayoutKind.Sequential)]
public struct ConnectionInfo
{
public uint cbSize;
public uint dwParams;
public uint dwFlags;
public uint dwPriority;
public int bExclusive;
public int bDisabled;
public Guid guidDestNet;
public IntPtr hWnd;
public uint uMsg;
public uint lParam;
public uint ulMaxCost;
public uint ulMinRcvBw;
public uint ulMaxConnLatency;
}
[DllImport("cellcore.dll")]
private static extern int ConnMgrMapURL(string pwszURL, ref Guid pguid, IntPtr pdwIndex);
[DllImport("cellcore.dll")]
private static extern int ConnMgrEstablishConnectionSync(ref ConnectionInfo ci, ref IntPtr phConnection, uint dwTimeout, ref uint pdwStatus);
[DllImport("cellcore.dll")]
private static extern IntPtr ConnMgrApiReadyEvent();
[DllImport("cellcore.dll")]
private static extern int ConnMgrReleaseConnection(IntPtr hConnection, int bCache);
[DllImport("coredll.dll")]
private static extern int CloseHandle(IntPtr hObject);
} Code: public void DoTcpConnection()
{
string url = "www.msn.com";
bool res = GPRSConnection.Setup("http://" + url + "/");
if (res)
{
TcpClient tc = new TcpClient(url, 80);
NetworkStream ns = tc.GetStream();
byte[] buf = new byte[100];
ns.Write(buf, 0, 100);
tc.Client.Shutdown(SocketShutdown.Both);
ns.Close();
tc.Close();
MessageBox.Show("Wrote 100 bytes");
}
else
{
MessageBox.Show("Connection establishment failed");
}
} |
|
#15
| |||
| |||
| Hi there, Very well, the answer is very simple, you need to know about port no. / name & it's usage, a little knowledge on protocols, i.e, TCP / UDP. Do a little research on google.com........... ![]() Learn with my posts...
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
|
#16
| |||
| |||
| u just try TCP/IP socket the u will get idea about socket programming , then move to blootuth. try this link. VB.NET Socket Programming suzett |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ERROR 2002 (HY000): Can't connect to local MySQL server through socket | Gopisoft | Database Support | 1 | 10-29-2007 02:07 AM |
| Socket programming in windows mobile 5.0 its support CAsyncSocket class? | theone | Windows Mobile | 1 | 07-25-2007 12:24 AM |
| What is the difference between Windows programming and database programming? | Arun | VB.NET Programming | 0 | 07-18-2007 07:58 AM |
| Socket Programming With PHP | Jeyaseelansarc | PHP Programming | 0 | 05-16-2007 01:33 AM |
| XML Socket Servers programming in Flash | Karpagarajan | Flash Actionscript Programming | 0 | 04-05-2007 03:00 AM |
Our Partners |