Advertisement
Guest User

Zataak

a guest
Aug 9th, 2009
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. ///////////////////////////////
  2. SERVER -- LISTENING FOR IMAGES
  3. //////////////////////////////
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Text;
  11. using System.Windows.Forms;
  12.  
  13. using System.IO;
  14. using System.Threading;
  15. using System.Net;
  16. using System.Net.Sockets;
  17.  
  18. namespace Server
  19. {
  20.     public partial class Form1 : Form
  21.     {
  22.         UdpClient server;
  23.         IPEndPoint remoteEP;
  24.  
  25.         public Form1(IPAddress camIP)
  26.         {
  27.             InitializeComponent();
  28.             Control.CheckForIllegalCrossThreadCalls = false;
  29.             server = new UdpClient(8050);
  30.             remoteEP = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0);
  31.         }
  32.  
  33.         private void timer1_Tick(object sender, EventArgs e)
  34.         {
  35.             Thread myth;
  36.             myth = new Thread(new System.Threading.ThreadStart(Image_Receiver)); // Start Thread Session
  37.             myth.Start();
  38.         }
  39.  
  40.         void Image_Receiver()
  41.         {
  42.             byte[] data = server.Receive(ref remoteEP);
  43.             MemoryStream ms = new MemoryStream(data);
  44.             PicBox.Image = Image.FromStream(ms); // Show The Image that Resaved as Binary Stream
  45.         }
  46.  
  47.         private void Form1_Activated(object sender, EventArgs e)
  48.         {
  49.             this.timer1.Enabled = true;
  50.         }
  51.  
  52.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  53.         {
  54.             server.Close();
  55.         }
  56.  
  57.     }
  58. }
  59.  
  60. ///////////////////////////////
  61. CLIENT -- SENDING IMAGES
  62. //////////////////////////////
  63.  
  64. private void timer1_Tick_1(object sender, EventArgs e)
  65.         {
  66.  
  67.             try
  68.             {
  69.                 MemoryStream ms = new MemoryStream();
  70.                 CamBox.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  71.                 byte[] arrImage = ms.GetBuffer();
  72.                 ms.Close();
  73.  
  74.            UdpClient socket;
  75.            IPEndPoint serverEP;
  76.  
  77.            socket = new UdpClient();
  78.                 serverEP = new IPEndPoint(IPAddress.Parse("81.106.68.10"), 8050);
  79.                 socket.Connect(serverEP);
  80.                 socket.Send(arrImage, arrImage.Length);
  81.            socket.close();
  82.             }
  83.             catch (Exception ex) { }
  84.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement