PDA使用WIFI传输文档到PC端怎么实现?求各位大侠不吝赐教~~~
如题,小生在这跪谢了!有参考的代码或者帖子各位不要藏着啊,全部往我这里砸吧,我不嫌多啊!!!!跪谢了~~~~ Wi-Fi PC 文档 WINCE PDA
[解决办法]
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Threading;
namespace PDA
{
public class WinCESockets
{
private const string DLLPATH = "\\windows\\coredll.dll"; // "kernel32";
///<summary>
///得到时间
///</summary>
[DllImport(DLLPATH)]
public static extern uint GetTickCount();
//建立全局变量
public Thread thread;
// 本地IP地址
public string m_tcpIPAddress;//服务器IP地址
//监听的端口
public int m_tcpListeningPort;
//本地IP
public string localIP;
public bool isConnect = false;
private static int buffer_size = 1024;
private static byte[] clientReceiveBytes = new byte[buffer_size];
private static Socket client_socket = null;
public WinCESockets()
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
localIP = ipAddress.ToString();
}
/*建立链接*/
public bool SocketsLink()
{
try
{
client_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ipadd = IPAddress.Parse(m_tcpIPAddress);
IPEndPoint ipe = new IPEndPoint(ipadd, m_tcpListeningPort);
try
{
client_socket.Connect(ipe);
isConnect = client_socket.Connected;
}
catch (SocketException e)
{
isConnect = client_socket.Connected;
}
//thread = new Thread(new ThreadStart(receiveData));//创建接收线程
//thread.Start();//启动接收线程,死循环接收数据
isConnect = client_socket.Connected;
return isConnect; /* "连接成功"; */
}
catch (Exception ee)
{
//MessageBox.Show(ee.Message);
isConnect = false;
return isConnect;
}
}
public void SocketsClose()
{
try
{
client_socket.Shutdown(SocketShutdown.Both);
client_socket.Close();
}
catch (Exception err)
{
;// MessageBox.Show(err.ToString());
}
}
/*发送字节数组*/
public bool SocketsSendByte(byte[] sendbuf, int sendlen)
{
try
{
client_socket.Send(sendbuf, sendlen, 0);
return true;
}
catch (Exception err)
{
return false;
}
}
public string receiveData()
{
int bytes=0;
try
{
if (client_socket.Available > 10)
{
bytes = client_socket.Receive(clientReceiveBytes, client_socket.Available, 0);
ASCIIEncoding encoding = new ASCIIEncoding();
string constructedString = encoding.GetString(clientReceiveBytes, 0, bytes);
return (constructedString);
}
else return "";
}
catch (Exception ex)
{
return "";//MessageBox.Show(ex.Message);
}
}
}
}