Windows Mobile上的GPRS连接 基于TcpClient
2010-05-06 21:56:00 来源:WEB开发网核心提示:ci, ref IntPtr phConnection, uint dwTimeout, ref uint pdwStatus);[DllImport("cellcore.dll")]private static extern IntPtr ConnMgrApiReadyEvent();[DllIm
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);
}
使用GPRSConnection class的时候, 先调用Setup方法创建连接,见以下代码:
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");
}
}
更多精彩
赞助商链接