using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net; // For Using Network Programming Classes
using System.Net.Sockets; // For Using Socket Classes
using System.IO; // For Input Output Streams Classes
using System.Threading; // For Multi Threading In the Same App
namespace send1
{
public partial class Form1 : Form
{
int groupPort = 6666;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("คลิกส่งละนะ");
send();
}
void send()
{
MessageBox.Show("เริ่ม");
Socket client_sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("255.255.255.255"), groupPort);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
FileStream fs = new FileStream(@"C:\test.png", FileMode.Open, FileAccess.Read);
BinaryReader binFile = new BinaryReader(fs);
byte[] downBuffer = new byte[1024000];
//byte[] downBuffer = Encoding.ASCII.GetBytes(binFile);
int bytesSize = 0;
while ((bytesSize = binFile.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
try
{
byte[] buffer = BitConverter.GetBytes(downBuffer.Length);
socket.SendTo(buffer, groupEP);
MessageBox.Show("ส่งภาพได้แล้วจ้า");
}
catch
{
MessageBox.Show("ยังส่งไมได้เลยน๊ะ");
}
}
}
}
}