using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.Serialization.Formatters.Binary;
namespace picturesend
{
public partial class Form1 : Form
{
UdpClient send, receive;
IPEndPoint sendpt, receivept;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(picsend));
t.IsBackground.CompareTo(true);
t.Start();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog mydialog = new OpenFileDialog();
if (mydialog.ShowDialog() == DialogResult.OK)
{
string path = mydialog.FileName;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] data = br.ReadBytes(Convert.ToInt16(fs.Length));
send = new UdpClient();
sendpt=new IPEndPoint(IPAddress.Parse("127.0.0.1"),3333);
send.Send(data,data.Length,sendpt);
send.Close();
}
}
public void picsend()
{
receive = new UdpClient(3333);
do
{
try
{
byte[] pic = receive.Receive(ref receivept);
using (MemoryStream ms = new MemoryStream(pic, 0, pic.Length))
{
ms.Write(pic, 0, pic.Length);
Image im = Image.FromStream(ms, true);
pictureBox1.Image = im;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
} while (true);
}
}
}