我要发送视频,可以说创建视频聊天,并使用MemoryStream-发送图像,编码为字节,但是出现此错误
我正在寻找这些问题的解决方案,但没有任何效果
这是实现发送的代码段。
const string ip = "127.0.0.1";
const int port = 9390;
byte[] buffer;
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(ip), port);
MemoryStream stream = new MemoryStream();
private void VideoSender()
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
//var endPoint =
socket.Connect(endPoint);
while (this.isTrue)
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
buffer = stream.ToArray();
socket.Send(buffer);
}
}
}
}
这是实现接收的代码。
static byte[] buffer = new byte[1000000];
MemoryStream stream = new MemoryStream(buffer);
private void Listener()
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
var endPoint = new IPEndPoint(IPAddress.Any, 9390);
socket.Bind(endPoint);
socket.Listen(5);
Socket client = socket.Accept();
while (this.isTrue)
{
client.Receive(buffer);
pictureBox1.Image = Image.FromStream(stream);
buffer = new byte[1000000];
}
}
这两张图片都在while(true)中,以便无延迟地发送和接收图像
我希望来自第一个程序的图像(视频)被发送并反映在第二个程序的pictureBox中,这将在两个pictureBox中都是视频效果。但是我在错误行中收到“参数无效”异常