本人学完C#不久,想做个局域网聊天软件```
所以请大家帮帮忙教我实现电脑与电脑之间的信息传递的部分。
————用什么犯法``怎样实现电脑之间的信息传递`````

解决方案 »

  1.   

    remoting应该是最简单的了吧,百度一下
      

  2.   

      什么是Remoting,简而言之,我们可以将其看作是一种分布式处理方式。从微软的产品角度来看,可以说Remoting就是DCOM的一种升级,它改善了很多功能,并极好的融合到.Net平台下。Microsoft? .NET Remoting 提供了一种允许对象通过应用程序域与另一对象进行交互的框架。这也正是我们使用Remoting的原因。为什么呢?在Windows操作系统中,是将应用程序分离为单独的进程。这个进程形成了应用程序代码和数据周围的一道边界。如果不采用进程间通信(RPC)机制,则在一个进程中执行的代码就不能访问另一进程。这是一种操作系统对应用程序的保护机制。然而在某些情况下,我们需要跨过应用程序域,与另外的应用程序域进行通信,即穿越边界。
    还有不懂就看网站视频:
    http://www.tmbm88.cn
    http://www.mostcc.cn
    http://www.100133.com
    http://www.007009.com
    http://www.57617.com
    http://bq361.cn
    http://www.57deal.cn
    http://www.3330888.cn
    http://www.20998.com.cn
    http://www.cqcwct.cn
    http://181810.com
      

  3.   

    remoting 看似简单, 问题会比使用 socket 多,
    还是使用 socket 吧
      

  4.   


    socket例子
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net.Sockets;
    using System.Net;
    using System.Threading;namespace mytcpchat
    {
        public partial class Form1 : Form
        {
            Socket c;
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
              
            }
             public void Client(IPEndPoint ServerIPEP)
            {
                try
                {
                    c = new Socket(ServerIPEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    c.Connect((EndPoint)ServerIPEP);
                    c.Send(System.Text.Encoding.Default.GetBytes("这是一个测试消息"));
                    byte[] data = new byte[2048];
                    int rect = c.Receive(data);
                    byte[] chat = new byte[rect];
                    Buffer.BlockCopy(data, 0, chat, 0, rect);
                    MessageBox.Show(System.Text.Encoding.Default.GetString(chat));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }        }        private void button1_Click(object sender, EventArgs e)
            {
                Client(new IPEndPoint(IPAddress.Parse("220.194.57.122"), 5566));
            }
        }
    }  服务端例子:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net.Sockets;
    using System.Net;
    using System.Threading;
    namespace mytcpserver
    {
        public partial class Form1 : Form
        {
            Socket s;
            IPEndPoint ServerIPEP;
            public Form1()
            {
                InitializeComponent();
            }
             public void  Server(int port)
            {
                ServerIPEP = new IPEndPoint(IPAddress.Any, port);
                s = new Socket(ServerIPEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                s.Bind((EndPoint)ServerIPEP);
                s.Listen(10);
                while (true)
                {
                    Socket uc = s.Accept();
                    byte[] data = new byte[2048] ;
                    int rect = uc.Receive(data);
                    byte[] chat = new byte[rect] ;
                    Buffer.BlockCopy(data, 0, chat, 0, rect);
                    MessageBox.Show("接收到来及客户端的消息"+uc.RemoteEndPoint.ToString()+System.Text.Encoding.Default.GetString(chat));
                    uc.Send(chat);
                }
            }
            private void Form1_Load(object sender, EventArgs e)
            {        }        private void button1_Click(object sender, EventArgs e)
            {
                Server(5566);
            }
        }
    }
      

  5.   

    使用Socket.协议嘛用TCP/UDP都行.
      

  6.   

    Remoting 最大的麻烦就是不能跨防火墙,用其实现后,在防火墙中设置一下~~~
    Remoting 实现起来比较简单~~~
      

  7.   

    使用 socket Remoting 是做分布式的