Как вывести в textBox значение Console.WriteLine("Data:{0}", str) - C#
Формулировка задачи:
Здравствуйте.
Подскажите пожалуйста как тут быть (
Решение задачи: «Как вывести в textBox значение Console.WriteLine("Data:{0}", str)»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- using System.Net;
- using System.Net.Sockets;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- private static Socket _socket = null;
- Byte[] buffer = { 0xFF, 0xFF, 0xFF, 0xFF, 0x55 };
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- IPEndPoint[] eps = { new IPEndPoint(IPAddress.Parse("77.220.184.198"), 27228) };
- _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
- _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3000);
- Thread recvThread = new Thread(new ThreadStart(recv));
- recvThread.Name = "Receive Thread";
- recvThread.Start();
- int nBytesSent = 0;
- for (int i = 0; i < eps.Length; i++)
- {
- nBytesSent = _socket.SendTo(buffer, eps[i]);
- }
- recvThread.Join();
- _socket.Shutdown(SocketShutdown.Both);
- _socket.Close();
- }
- private void recv()
- {
- CheckForIllegalCrossThreadCalls = false;
- Thread.Sleep(50);
- byte[] buff = new byte[1024 * 100];
- int nBytes = 1;
- IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0);
- EndPoint ep = (EndPoint)iep;
- nBytes = _socket.ReceiveFrom(buff, ref ep);
- string str = System.Text.Encoding.ASCII.GetString(buff, 5, nBytes);
- textBoxReceive.Text = string.Format("Data:{0}", str);
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д