Beispiel #1
0
        /// <summary>
        /// 关闭客户端录音
        /// </summary>
        private void closeSocket()
        {
            // close sound capture
            directSoundCapture.Stop();
            directSoundCapture = null;

            // Release the socket.
            byte[] msg = Encoding.UTF8.GetBytes("关闭连接" + "<EOF>");
            socket.Send(msg);
            socket.Shutdown(SocketShutdown.Both);
            socket.Close();
        }
Beispiel #2
0
        /// <summary>
        /// 初始化Socket基础连接信息
        /// </summary>
        private void initSocket()
        {
            Console.WriteLine("客户端开启Socket......");
            Console.WriteLine("客户端开启Socket......" + Dns.GetHostName());
            IPHostEntry ipHostInfo = Dns.GetHostEntry(Setting.IP_ADDRESS);
            IPAddress   ipAddress  = ipHostInfo.AddressList[0];
            IPEndPoint  remoteEP   = new IPEndPoint(ipAddress, Setting.PORT);

            // Create a TCP/IP  socket.
            socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(remoteEP);// 与远端建立socket连接

            directSoundCapture = new DirectSoundCapture();

            directSoundCapture.LocalSocket    = socket;           //客户端Socket实例对象
            directSoundCapture.RemoteEndPoint = remoteEP;         //连接远程服务端点
            directSoundCapture.NotifyNum      = 1024;             //每次发送的数量
            directSoundCapture.Intptr         = new IntPtr(1024); //窗口句柄
            directSoundCapture.InitVoice();                       // 初始化声音设备
            directSoundCapture.StartVoiceCapture();               //开启声音采集

            Console.WriteLine("客户端开启Socket...并初始化参数配置完成.");
        }