liuviking 发表于 2012-9-13 20:30
不需要,socket就建立一个,连接起来了之后就是双向的。
///////////////////////////////////////////////////////接收数据///////////////////////////////
private static byte[] AlarmData=new byte[1024];
void ReceiveData()
{
int recv;
string stringData;
while (true)
{
recv = clientSocket.Receive(AlarmData);
stringData = Encoding.ASCII.GetString(AlarmData, 0, recv);
if (stringData !=null)
{
mp3.play();
}
}
}
void AcceptConn(IAsyncResult iar)
{
Socket oldserver = (Socket)iar.AsyncState;
clientSocket = oldserver.EndAccept(iar);
Thread receiver = new Thread(new ThreadStart(ReceiveData));
receiver.Start();
}
void menuItem5_Click(object sender, EventArgs e)
{
InitWIFI(ControlIp, Port);//初始化WIFI
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.1.1"),2001);
clientSocket.Bind(iep);
clientSocket.Listen(5);
clientSocket.BeginAccept(new AsyncCallback(AcceptConn), clientSocket);
}
我想问下,这个怎么还是无法接收到数据呢?下位机发送的是“0x11”的字符串 |