/// <summary> /// 文字列を取得する /// </summary> /// <returns></returns> public String getText() { String result = null; DataPacket packet = null; byte[] bytes = base.recv(); packet = new DataPacket(bytes); if (packet.isSendPROPERTY()) { result = m_encoding.GetString(packet.m_body); result = result.Replace('\0',' '); } return result; }
/// <summary> /// データを受信する /// </summary> /// <returns>受信データ</returns> public override object recive() { IPEndPoint remoteEP = null; byte[] recvByte = UdpClient.Receive(ref remoteEP); DataPacket packet = null; packet = new DataPacket(recvByte); if (packet.isSendMSG()) { return Encoding.GetString(packet.m_body); } else { return null; } }
/// <summary> /// カメラ映像を取得する /// </summary> /// <returns></returns> public Bitmap getImage() { Bitmap result = null; DataPacket packet = null; byte[] bytes = base.recv(); packet = new DataPacket(bytes); if (packet.isSendIMG()) { byte[] recv = packet.m_body; MemoryStream ms = new MemoryStream(recv); try { result = new Bitmap(ms); } catch (ArgumentException ex) { Console.WriteLine("不正パケットのため破棄"); } } return result; }
/// <summary> /// データを送信する /// </summary> /// <param name="data"></param> /// <param name="length"></param> /// <param name="hostname"></param> /// <param name="portnum"></param> public override void send(byte[] data, int length, String hostname, int portnum) { DataPacket packet = new DataPacket(DataPacket.TYPE_SENDMSG,data); UdpClient.Send(packet.m_data, packet.m_data.Length, hostname, portnum); }
/// <summary> /// 通信監視スレッドにより実行される /// </summary> private void threadRecive_Start() { bool responseWait = false; while (true) { if (TextReciver.available() > 0) { Object recv = TextReciver.recive(); if (recv != null) { String data = (String)recv; showText(data); //カメラ映像を受信するためにServerに接続する if (!m_cameraImageTcpClient.isConnect()) { responseWait = false; m_cameraImageTcpClient.connect("suzuki-PC", 10020); } } } if (m_cameraImageTcpClient.isConnect()) { if (!responseWait) { DataPacket packet = new DataPacket(DataPacket.TYPE_GETIMG, null); m_cameraImageTcpClient.send(packet.toByteArray()); responseWait = true; } if (m_cameraImageTcpClient.available()) { try { Bitmap bmp = m_cameraImageTcpClient.getImage(); showImage(bmp); } catch (ArgumentException ex) { Console.WriteLine("不正パケットのため破棄"); } responseWait = false; //byte[] recv = m_cameraImageTcpClient.getImage(); //MemoryStream ms = new MemoryStream(recv); //try //{ // Bitmap bmp = new Bitmap(ms); // showImage(bmp); //} //catch (ArgumentException ex) //{ // Console.WriteLine("不正パケットのため破棄"); //} //responseWait = false; } } Thread.Sleep(100); } }