首页 > 代码库 > C# 视频流操作

C# 视频流操作

发送视频流

 1   void SendVideoBuffer(object bufferIn)
 2         {
 3             try
 4             {
 5                TcpClient tcp = new TcpClient(PeerIP_TXT.Text, 6000);
 6                NetworkStream ns = tcp.GetStream();
 7                 Image buffer = (Image)bufferIn;
 8                 buffer.Save(ns, System.Drawing.Imaging.ImageFormat.Jpeg);
 9                 ns.Close();
10                 tcp.Close();
11             }
12             catch (Exception) { }
13         }


接收视频流

 1    Socket server_sock;
 2         void server()
 3         {
 4             try
 5             {
 6                 server_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 7                 server_sock.Bind(new IPEndPoint(IPAddress.Any, 6000));
 8                 server_sock.Listen(-1);
 9 
10                 while (true)
11                 {
12                     try
13                     {
14                         Socket new_socket = server_sock.Accept();
15                         NetworkStream ns = new NetworkStream(new_socket);
16                         pictureBox_Remote.Image = Image.FromStream(ns);
17                         ns.Close();
18                         new_socket.Close();
19                     }
20                     catch (Exception)
21                     {
22                     }
23                 }
24             }
25             catch(Exception){}
26 
27         }

 

C# 视频流操作