UDP Packet Generator

Tonight I need a UDP Packet generator, so I thought just to paste it here so I can help anybody looking for something like that. I have a few files I want to transfer using UDP to another machine. Remember that UDP does not warranty delivery.

Change the localhost to the destination IP as well as the destination port number.

System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();

            client.Connect("localhost", 601);

            System.IO.DirectoryInfo info = new System.IO.DirectoryInfo("C:\\temp\\udp");
            System.IO.FileInfo [] fileInfo = info.GetFiles();

            foreach (System.IO.FileInfo inf in fileInfo)
            {
                string filePath = inf.FullName;

                StreamReader readStream = System.IO.File.OpenText(filePath);

                byte [] stre = System.Text.Encoding.Unicode.GetBytes(readStream.ReadToEnd());

                readStream.Close();

                client.Send(stre, stre.Length);
            }

            client.Close();

Cheers

Al

Published Tuesday, June 24, 2008 11:18 PM by albertpascual
Filed under: , , ,

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required)