zoukankan      html  css  js  c++  java
  • 简单实现进程间的通信

    AppOne:

    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    
    namespace AppOne
    {
        class Program
        {
            static void Main(string[] args)
            {
                Socket s = new Socket(AddressFamily.InterNetwork,
                              SocketType.Stream, ProtocolType.Tcp);
                IPAddress IPA = IPAddress.Parse("172.17.13.77");
                IPEndPoint ipEp = new IPEndPoint(IPA, 5567);
                s.Bind(ipEp);
                s.Listen(1);
                Socket ms = s.Accept();
                Console.WriteLine("connecting success");
                Console.WriteLine("please input a text");
                string message = Console.ReadLine();
    
                byte[] buffer = new byte[1024];
                buffer = Encoding.UTF8.GetBytes(message);
                ms.Send(buffer, buffer.Length, SocketFlags.None);
    
                Console.ReadKey();
                ms.Close();
                s.Close();
            }
        }
    }
    View Code

    AppTwo:

    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    
    namespace AppTwo
    {
        class Program
        {
            static void Main(string[] args)
            {
                Socket s = new Socket(AddressFamily.InterNetwork,
                                   SocketType.Stream, ProtocolType.Tcp);
                 
                IPEndPoint rIPEP = new IPEndPoint(IPAddress.Parse("172.17.13.77"), 5567);
                s.Connect(rIPEP);
     
                byte[] buffer = new byte[1024];
                int rbn;
                rbn = s.Receive(buffer);
    
                string message = Encoding.UTF8.GetString(buffer);
                Console.WriteLine(message);
                Console.ReadKey(true);
                s.Close();
            }
        }
    }
    View Code

    运行结果如下图所示:

  • 相关阅读:
    矩阵树定理
    随机乱搞算法
    数学
    BZOJ——3412: [Usaco2009 Dec]Music Notes乐谱
    BZOJ—— 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
    洛谷—— P2884 [USACO07MAR]每月的费用Monthly Expense
    洛谷—— P2417 课程
    洛谷—— P1577 切绳子
    COGS 2598. 美丽的感觉
    10.23 模拟赛
  • 原文地址:https://www.cnblogs.com/jizhiqiliao/p/9884079.html
Copyright © 2011-2022 走看看