C#中TCP/IP数据传送问题
我想做个象VNC那种远程软件
我现在能让CLIENT端截当前桌面的图,但是发送不到服务端,我对于TCP/IP这块编程不是很懂,请问该怎么做啊
CLIENT:
private void button2_Click(object sender, EventArgs e)
{
Image MyImg = GetDesktopImage();
MemoryStream ms = new MemoryStream();
MyImg.Save(ms, ImageFormat.Jpeg);
byte[] send = ms.GetBuffer();
try
{
TcpClient m_client = new TcpClient("127.0.0.1", 12345);
NetworkStream stream = m_client.GetStream();
stream.Write(send, 0, send.Length);
stream.Close();
m_client.Close();
}
catch (SocketException aa)
{
MessageBox.Show(aa.Message);
}
}
--------------------------------------------------------------------------
SEVER:
TcpListener m_server;
TcpClient m_client;
private void Form1_Load(object sender, EventArgs e)
{
m_server = new TcpListener(12345);
try
{
//m_server=server;
textBox1.Text = "已经开始了";
m_server.Start();
Thread m_thread = new Thread(new ThreadStart(GetConn));//开启线成
m_thread.Start();//运行
}
catch (SocketException ae)
{
MessageBox.Show("错误源" + ae.Source + "表示" + ae.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void GetConn()//线成函数
{
m_client = m_server.AcceptTcpClient();
TcpClient c = this.m_client;
Thread m_thread = new Thread(new ThreadStart(GetConn));
m_thread.Start();
NetworkStream stream = c.GetStream();
byte[] recv = new byte[999999];
string msg = "";
string temp;
try
{
int a = 0;
a = stream.Read(recv, 0, 999999);
if (a > 0)
{
MemoryStream ms = new MemoryStream(recv);
Image image = Image.FromStream(ms, true);
pictureBox1.Image = image;
}
stream.Close();
c.Close();
}
catch (SocketException es)
{
MessageBox.Show("错误源" + es.Source + "表示" + es.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}