<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=305714&amp;view=findpost&amp;p=2615684</guid>
        <pubDate>Tue, 08 Jun 2010 21:00:36 +0000</pubDate>
        <title>Не удается отправить файл по UDP</title>
        <link>https://forum.sources.ru/index.php?showtopic=305714&amp;view=findpost&amp;p=2615684</link>
        <description><![CDATA[Vorpuhc: Здравствуйте помогите пожалуйста доделать Лабу по ВС. Выскакивает ошибка типо не хватает памяти. Сообщение, отправленное на сокет датаграмм, было больше, чем буфер внутренних сообщений или был превышен иной сетевой параметр. Также возможно, что буфер для принятия сообщения был меньше, чем размер сообщения. Но если уменьшить размен Скриншота в 2 раза все нормально(((. <br>
<br>
Сервер<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">using System;</div><div class="code_line">using System.Collections.Generic;</div><div class="code_line">using System.ComponentModel;</div><div class="code_line">using System.Data;</div><div class="code_line">using System.Drawing;</div><div class="code_line">using System.Text;</div><div class="code_line">using System.Windows.Forms;</div><div class="code_line">using System.Drawing.Imaging;</div><div class="code_line">using System.Net;</div><div class="code_line">using System.Net.Sockets;</div><div class="code_line">using System.IO;</div><div class="code_line">&nbsp;</div><div class="code_line">namespace lab</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;public partial class Form1 : Form</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;private static Bitmap bmpScreenshot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;private static Graphics gfxScreenshot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Socket s;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;EndPoint remep;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;byte[] buffer;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;public Form1()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InitializeComponent();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.Bind(new IPEndPoint(IPAddress.Parse(&quot;0.0.0.0&quot;), 5000));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;remep = new IPEndPoint(IPAddress.Any, 6000);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(true)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer = new byte[100];</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.ReceiveFrom(buffer, ref remep);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string str = Encoding.ASCII.GetString(buffer, 0, buffer.Length);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(str.TrimEnd(&#39;{text}&#39;) ==&quot;send_to_me&quot;)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MemoryStream ms = new MemoryStream();</div><div class="code_line">ScreenShot().Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);</div><div class="code_line">byte[] result = ms.ToArray();</div><div class="code_line">s.SendBufferSize = 100000000;</div><div class="code_line">s.ReceiveBufferSize = 100000000;</div><div class="code_line">s.SendTo(result, remep);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Bitmap ScreenShot()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Create a graphics object from the bitmap</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gfxScreenshot = Graphics.FromImage(bmpScreenshot);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Take the screenshot from the upper left corner to the right bottom corner</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, new Size(Screen.PrimaryScreen.Bounds.Size.Width/1,Screen.PrimaryScreen.Bounds.Size.Height/1) , CopyPixelOperation.SourceCopy);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Save the screenshot to the specified path that the user has chosen</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return bmpScreenshot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
Клиент<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">using System;</div><div class="code_line">using System.Collections.Generic;</div><div class="code_line">using System.ComponentModel;</div><div class="code_line">using System.Data;</div><div class="code_line">using System.Drawing;</div><div class="code_line">using System.Linq;</div><div class="code_line">using System.Text;</div><div class="code_line">using System.Windows.Forms;</div><div class="code_line">using System.Net.Sockets;</div><div class="code_line">using System.Net;</div><div class="code_line">using System.IO;</div><div class="code_line">&nbsp;</div><div class="code_line">namespace cleint</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;public partial class Form1 : Form</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;private static Bitmap bmpScreenshot;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Socket s;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;EndPoint remep;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;byte[] buffer;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;public Form1()</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InitializeComponent();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;remep = new IPEndPoint(IPAddress.Any, 7000);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer = new byte[100000000];</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;private void button1_Click(object sender, EventArgs e)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.SendTo(Encoding.ASCII.GetBytes(&quot;send_to_me&quot;), new IPEndPoint(IPAddress.Parse(textBox1.Text),5000));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.ReceiveBufferSize = 100000000;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.SendBufferSize = 100000000[CODE=C#]</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.ReceiveFrom(buffer, ref remep);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bitmap bt = new Bitmap(new MemoryStream(buffer));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.CreateGraphics().DrawImage(bt, 0, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
<br>
Задание: Написать UDP сервер, который прослушивает некоторый порт и ждет подключения клиента, если клиент подключается и посылает некоторую команду, сервер снимает образ экрана и отсылает его клиенту.<br>
Написать UDP клиент, который, по нажатии некоторой кнопки,  посылает серверу команду и получает копию экрана и выводит ее у себя на форме.<br>
<br>
Буду очень признателен всем людям которые помогутт уже просто голова не варит(((]]></description>
        <author>Vorpuhc</author>
        <category>.NET: Распределенные приложения</category>
      </item>
	
      </channel>
      </rss>
	