0

在此示例中,我必须做什么才能将此代码从套接字应用程序重写为邮槽互通:

// Server:


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.Net.Sockets;
using System.Net;

// Server

namespace OS
{
    public partial class Server : Form
    {
        Socket servsoc;
        byte[] buf = new byte[1024];
        public Server()
        {
            InitializeComponent();
        }

        private void Start_Click(object sender, EventArgs e)
        {
            servsoc.Receive(buf);
            Out1.Text = Encoding.ASCII.GetString(buf);
            Array.Clear(buf, 0, buf.Length);
        }

        private void Server_Load(object sender, EventArgs e)
        {
            CreateSocket(ref servsoc);
        }

        private void Server_Leave(object sender, EventArgs e)
        {
            servsoc.Close();
        }
    }
}

Client1:

using System.Windows.Input;
using System.Net.Sockets;
using System.Net;

namespace Client1
{
    public partial class Client1 : Form
    {
        Socket send;
        EndPoint endtarget;
        public Client1()
        {
            InitializeComponent();
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
            send.Close();
        }

        private void Client1_Load(object sender, EventArgs e)
        {
            Out3.Text = InputLanguage.CurrentInputLanguage.Culture.EnglishName;
            Out1.Text = Convert.ToString(SystemColors.ActiveBorder.R)+ " " + Convert.ToString(
 SystemColors.ActiveBorder.G) + " " + Convert.ToString( SystemColors.ActiveBorder.B);
             Out2.Text = Convert.ToString(SystemColors.Desktop.R) + " " + Convert.ToString(SystemColors.Desktop.G) + " " + Convert.ToString(SystemColors.Desktop.B);
             CreateSocket(ref send, ref endtarget);
        }

        private void Send1_Click(object sender, EventArgs e)
        {
            send.SendTo(Encoding.ASCII.GetBytes(Out1.Text), endtarget);
        }

        private void Send2_Click(object sender, EventArgs e)
        {
            send.SendTo(Encoding.ASCII.GetBytes(Out2.Text), endtarget);
        }

        private void Send3_Click(object sender, EventArgs e)
        {
            send.SendTo(Encoding.ASCII.GetBytes(Out3.Text), endtarget);
        }
    }
}
4

0 回答 0