udp广播----------如何同时传播文字和图片? rtCILENT 和 SERVER 都使用RICHTEXTBOX 控件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 肯定要分开传,建立排队机制要传输这些内容,首先要把它们转换为byte数组真个题太大,不好一一说,你还是自己去学习,当中有疑问的再问如果有耐心,建议去下载一个myicq的源码来看看,这是开放源码的 QQ里把函数告诉你了.但是把图片放到stream里面怎么样让richtextbox显示我不知道. 我的意思是:client 的richtextbox怎么样发送图片+文字的内容,server如何接收 ?继续收集意见 你定义传协议,简单的文字加图片信息可以定义如下:<Message>sfsddfsd<IMG>SDFSD</IMG>SFS<IMG>SDFS</IMG></Message>;byte是可以转成字符的,分解后把IMG部分转成byte用Image类加载就可以还原图象. {\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fcharset134 \'cb\'ce\'cc\'e5;}}\viewkind4\uc1\pard\lang2052\f0\fs18{\pict\wmetafile8\picw5396\pich3888\picwgoal3059\pichgoal2204 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}\par}例如这样一个图片的rtf代码,怎么样把它再变成图片 ?----------------------------------------------------楼上那位老师的定义传协议,有朋友能清楚的讲述一下吗 ?谢谢 这么快就结了?我昨天培训去了,很无奈啊。我做了一个,很简单,运行良好,帖下面了。有一点要注意的,UPD包是限大小的,包太大是发不出去的,好象是4096字节,大的要分包发,我的程序里没有分包。图片用COPY&PASTE搞。using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Net.Sockets;using System.Net;using System.Threading;using System.IO;namespace RTFMessenger{ /// <summary> /// Summary description for Form1. /// </summary> public class mainForm : System.Windows.Forms.Form { private System.Windows.Forms.RichTextBox rtfSend; private System.Windows.Forms.Splitter splitter; private System.Windows.Forms.RichTextBox rtfReceive; private System.Windows.Forms.Button btnSend; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public mainForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // thread = new Thread(new ThreadStart(Listen)); thread.Start(); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.rtfSend = new System.Windows.Forms.RichTextBox(); this.splitter = new System.Windows.Forms.Splitter(); this.rtfReceive = new System.Windows.Forms.RichTextBox(); this.btnSend = new System.Windows.Forms.Button(); this.SuspendLayout(); // // rtfSend // this.rtfSend.Dock = System.Windows.Forms.DockStyle.Top; this.rtfSend.Location = new System.Drawing.Point(0, 0); this.rtfSend.Name = "rtfSend"; this.rtfSend.Size = new System.Drawing.Size(292, 96); this.rtfSend.TabIndex = 0; this.rtfSend.Text = ""; // // splitter // this.splitter.Dock = System.Windows.Forms.DockStyle.Top; this.splitter.Location = new System.Drawing.Point(0, 96); this.splitter.Name = "splitter"; this.splitter.Size = new System.Drawing.Size(292, 3); this.splitter.TabIndex = 1; this.splitter.TabStop = false; // // rtfReceive // this.rtfReceive.Dock = System.Windows.Forms.DockStyle.Top; this.rtfReceive.Location = new System.Drawing.Point(0, 99); this.rtfReceive.Name = "rtfReceive"; this.rtfReceive.Size = new System.Drawing.Size(292, 133); this.rtfReceive.TabIndex = 2; this.rtfReceive.Text = ""; // // btnSend // this.btnSend.Location = new System.Drawing.Point(216, 240); this.btnSend.Name = "btnSend"; this.btnSend.TabIndex = 3; this.btnSend.Text = "Send"; this.btnSend.Click += new System.EventHandler(this.btnSend_Click); // // mainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.btnSend); this.Controls.Add(this.rtfReceive); this.Controls.Add(this.splitter); this.Controls.Add(this.rtfSend); this.Name = "mainForm"; this.Text = "mainForm"; this.Closing += new System.ComponentModel.CancelEventHandler(this.mainForm_Closing); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new mainForm()); }//****************************************************************************// 只需要看以下的代码,另外上面构造的时候开了一个新线程 private Thread thread; private void Listen() { int port = 39763; UdpClient listener = new UdpClient(port); while(true) { try { IPEndPoint ipep = null; byte[] bytes = listener.Receive(ref ipep); this.Invoke(new dele(load), new object[]{bytes}); } catch(Exception) { break; } } listener.Close (); } private delegate void dele(byte[] bytes); private void load(byte[] bytes) { MemoryStream stream = new MemoryStream(bytes); rtfReceive.LoadFile(stream,RichTextBoxStreamType.RichText); stream.Close(); } private void Send() { int port = 39763; UdpClient sender = new UdpClient(); IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); MemoryStream stream = new MemoryStream(); rtfSend.SaveFile(stream,RichTextBoxStreamType.RichText); byte[] bytes = stream.GetBuffer(); sender.Send(bytes, bytes.Length, ipep); stream.Close(); } private void btnSend_Click(object sender, System.EventArgs e) { Send(); } private void mainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { thread.Abort(); } }} C# (C/S)生成安装包的问题.... 请教一个sql难题 winform窗口显示问题 哪位大虾能帮我提供一个自动显示题目的模版,不胜感激 pictureBox中添加lable子控件 子控件会随着鼠标移动 但移动时会频闪请问咋解决 快被折磨死了,程序运行上几次就会出现这个错误,晕了! C#中如何枚举WINDOWS的字体(高手请进) ★★★怎样画一个与Vs.net2003IDE上一样的平面菜单?? .NET安装问题,急!!!! 挑战高手哦!欢迎挑战关于ftp自动上传的问题?分不够的只能加送祝福了! 请教listbox中怎样判断有没有item被选中 怎样取得ListBox中被选中的值?
<Message>sfsddfsd<IMG>SDFSD</IMG>SFS<IMG>SDFS</IMG></Message>;
byte是可以转成字符的,分解后把IMG部分转成byte用Image类加载就可以还原图象.
\viewkind4\uc1\pard\lang2052\f0\fs18{\pict\wmetafile8\picw5396\pich3888\picwgoal3059\pichgoal2204
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
}\par
}
例如这样一个图片的rtf代码,怎么样把它再变成图片 ?
----------------------------------------------------楼上那位老师的定义传协议,有朋友能清楚的讲述一下吗 ?
谢谢
我做了一个,很简单,运行良好,帖下面了。
有一点要注意的,UPD包是限大小的,包太大是发不出去的,好象是4096字节,大的要分包发,我的程序里没有分包。图片用COPY&PASTE搞。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.IO;namespace RTFMessenger
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class mainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox rtfSend;
private System.Windows.Forms.Splitter splitter;
private System.Windows.Forms.RichTextBox rtfReceive;
private System.Windows.Forms.Button btnSend;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public mainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
thread = new Thread(new ThreadStart(Listen));
thread.Start();
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.rtfSend = new System.Windows.Forms.RichTextBox();
this.splitter = new System.Windows.Forms.Splitter();
this.rtfReceive = new System.Windows.Forms.RichTextBox();
this.btnSend = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// rtfSend
//
this.rtfSend.Dock = System.Windows.Forms.DockStyle.Top;
this.rtfSend.Location = new System.Drawing.Point(0, 0);
this.rtfSend.Name = "rtfSend";
this.rtfSend.Size = new System.Drawing.Size(292, 96);
this.rtfSend.TabIndex = 0;
this.rtfSend.Text = "";
//
// splitter
//
this.splitter.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter.Location = new System.Drawing.Point(0, 96);
this.splitter.Name = "splitter";
this.splitter.Size = new System.Drawing.Size(292, 3);
this.splitter.TabIndex = 1;
this.splitter.TabStop = false;
//
// rtfReceive
//
this.rtfReceive.Dock = System.Windows.Forms.DockStyle.Top;
this.rtfReceive.Location = new System.Drawing.Point(0, 99);
this.rtfReceive.Name = "rtfReceive";
this.rtfReceive.Size = new System.Drawing.Size(292, 133);
this.rtfReceive.TabIndex = 2;
this.rtfReceive.Text = "";
//
// btnSend
//
this.btnSend.Location = new System.Drawing.Point(216, 240);
this.btnSend.Name = "btnSend";
this.btnSend.TabIndex = 3;
this.btnSend.Text = "Send";
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
//
// mainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.btnSend);
this.Controls.Add(this.rtfReceive);
this.Controls.Add(this.splitter);
this.Controls.Add(this.rtfSend);
this.Name = "mainForm";
this.Text = "mainForm";
this.Closing += new System.ComponentModel.CancelEventHandler(this.mainForm_Closing);
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new mainForm());
}//****************************************************************************
// 只需要看以下的代码,另外上面构造的时候开了一个新线程 private Thread thread; private void Listen()
{
int port = 39763; UdpClient listener = new UdpClient(port); while(true)
{
try
{
IPEndPoint ipep = null; byte[] bytes = listener.Receive(ref ipep);
this.Invoke(new dele(load), new object[]{bytes});
}
catch(Exception)
{
break;
}
} listener.Close ();
} private delegate void dele(byte[] bytes); private void load(byte[] bytes)
{
MemoryStream stream = new MemoryStream(bytes);
rtfReceive.LoadFile(stream,RichTextBoxStreamType.RichText);
stream.Close();
}
private void Send()
{
int port = 39763;
UdpClient sender = new UdpClient();
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); MemoryStream stream = new MemoryStream();
rtfSend.SaveFile(stream,RichTextBoxStreamType.RichText);
byte[] bytes = stream.GetBuffer();
sender.Send(bytes, bytes.Length, ipep);
stream.Close();
} private void btnSend_Click(object sender, System.EventArgs e)
{
Send();
} private void mainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
thread.Abort();
}
}
}