当前位置: 首页>>代码示例>>C#>>正文


C# IPEndPoint.ToString方法代码示例

本文整理汇总了C#中IPEndPoint.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# IPEndPoint.ToString方法的具体用法?C# IPEndPoint.ToString怎么用?C# IPEndPoint.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPEndPoint的用法示例。


在下文中一共展示了IPEndPoint.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main()
    {
        byte[] data = new byte[1024];
          	string input, stringData;
          	UdpClient server = new UdpClient("127.0.0.1", 9877);

        IPEndPoint sender = new IPEndPoint(IPAddress.Any, 9876);

        string welcome = "Hello, are you there?";
        data = Encoding.ASCII.GetBytes(welcome);
        server.Send(data, data.Length);

        data = server.Receive(ref sender);

        Console.WriteLine("Message received from {0}:", sender.ToString());
        stringData = Encoding.ASCII.GetString(data, 0, data.Length);
        Console.WriteLine(stringData);

        while(true){
            input = Console.ReadLine();
            if (input == "exit")
                break;

                server.Send(Encoding.ASCII.GetBytes(input), input.Length);
             	data = server.Receive(ref sender);
        }
        Console.WriteLine("Stopping client");
        server.Close();
    }
开发者ID:Kaerit,项目名称:IsoMonksComm,代码行数:29,代码来源:client.cs

示例2: StartListener

 private static void StartListener()
 {
     bool done = false;
     IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
     UdpClient listener = new UdpClient(groupEP);
     Log.Notice("Listener", "Waiting for broadcast");
     try
     {
         while (!done)
         {
             byte[] bytes = listener.Receive(ref groupEP);
             Log.Info("Listener", "Client " + groupEP.ToString() + " is trying to connect");
             listener.Connect(groupEP);
             Log.Succes("Listener", "Listener connected to client " + groupEP.ToString());
             done = true;
             //TODO - rest of district server connecting
         }
     }
     catch (Exception e)
     {
         FrameWork.Logger.Log.Error("Listener", e.ToString());
     }
     finally
     {
         listener.Close();
     }
 }
开发者ID:harleyknd1,项目名称:rAPB,代码行数:27,代码来源:Listener.cs

示例3: Main

 public static int Main()
 {
     bool done = false;
     UdpClient listener = new UdpClient(listenPort);
     IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
     string received_data;
     byte[] receive_byte_array;
     try
     {
         while (!done)
         {
             Console.WriteLine("Waiting for broadcast");
             // this is the line of code that receives the broadcase message.
             // It calls the receive function from the object listener (class UdpClient)
             // It passes to listener the end point groupEP.
             // It puts the data from the broadcast message into the byte array
             // named received_byte_array.
             // I don't know why this uses the class UdpClient and IPEndPoint like this.
             // Contrast this with the talker code. It does not pass by reference.
             // Note that this is a synchronous or blocking call.
             receive_byte_array = listener.Receive(ref groupEP);
             Console.WriteLine("Received a broadcast from {0}", groupEP.ToString());
             received_data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);
             Console.WriteLine("data follows \n{0}\n\n", received_data);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
     listener.Close();
     return 0;
 }
开发者ID:Lrss,项目名称:P3,代码行数:33,代码来源:Program.cs

示例4: Main

    public static void Main()
    {
        byte[] data = new byte[1024];
          IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9876);
          UdpClient newsock = new UdpClient(ipep);

          Console.WriteLine("Waiting for a client...");

          IPEndPoint sender = new IPEndPoint(IPAddress.Any, 9877);

          data = newsock.Receive(ref sender);

          Console.WriteLine("Message received from {0}:", sender.ToString());
          Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));

          string msg = Encoding.ASCII.GetString(data, 0, data.Length);
          data = Encoding.ASCII.GetBytes(msg);
          newsock.Send(data, data.Length, sender);

          while(true){
         data = newsock.Receive(ref sender);

         Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));
         newsock.Send(data, data.Length, sender);
          }
    }
开发者ID:Kaerit,项目名称:IsoMonksComm,代码行数:26,代码来源:server.cs

示例5: Start

 // Use this for initialization
 void Start()
 {
     // Set up Server End Point for sending packets.
     IPHostEntry serverHostEntry = Dns.GetHostEntry(serverIp);
     IPAddress serverIpAddress = serverHostEntry.AddressList[0];
     serverEndPoint = new IPEndPoint(serverIpAddress, serverPort);
     Debug.Log("Server IPEndPoint: " + serverEndPoint.ToString());
     // Set up Client End Point for receiving packets.
     IPHostEntry clientHostEntry = Dns.GetHostEntry(Dns.GetHostName());
     IPAddress clientIpAddress = IPAddress.Any;
     foreach (IPAddress ip in clientHostEntry.AddressList) {
         if (ip.AddressFamily == AddressFamily.InterNetwork) {
             clientIpAddress = ip;
         }
     }
     clientEndPoint = new IPEndPoint(clientIpAddress, serverPort);
     Debug.Log("Client IPEndPoint: " + clientEndPoint.ToString());
     // Create socket for client and bind to Client End Point (Ip/Port).
     clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     try {
         clientSocket.Bind(clientEndPoint);
     }
     catch (Exception e) {
         Debug.Log("Winsock error: " + e.ToString());
     }
 }
开发者ID:Victory-Game-Studios,项目名称:Oldentide,代码行数:27,代码来源:NetworkInterface.cs

示例6: Main

   public static void Main()
   {
      byte[] data = new byte[1024];
      string input, stringData;
      UdpClient udpClient = new UdpClient("127.0.0.1", 9999);

      IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);

      string welcome = "Hello";
      data = Encoding.ASCII.GetBytes(welcome);
      udpClient.Send(data, data.Length);

      data = udpClient.Receive(ref sender);

      Console.WriteLine("Message received from {0}:", sender.ToString());
      stringData = Encoding.ASCII.GetString(data, 0, data.Length);
      Console.WriteLine(stringData);

      while(true)
      {
         input = Console.ReadLine();
         udpClient.Send(Encoding.ASCII.GetBytes(input), input.Length);
         data = udpClient.Receive(ref sender);
         stringData = Encoding.ASCII.GetString(data, 0, data.Length);
         Console.WriteLine(stringData);
      }
      udpClient.Close();
   }
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:28,代码来源:udpclient.cs

示例7: StartListener

    public void StartListener()
    {
        bool done = false;

        UdpClient listener = new UdpClient(listenPort);
        IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);

        try
        {
            while (!done)
            {
                Console.WriteLine("Waiting for broadcast");
                byte[] bytes = listener.Receive( ref groupEP);

                Console.WriteLine("Received broadcast from {0} :\n {1}\n",
                    groupEP.ToString(),
                    Encoding.ASCII.GetString(bytes,0,bytes.Length));
            }

        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            listener.Close();
        }
    }
开发者ID:eraumotorsports,项目名称:carLogger,代码行数:29,代码来源:BroadcastListener.cs

示例8: ToString_Compare_Success

        public static void ToString_Compare_Success()
        {
            IPEndPoint ep = new IPEndPoint(testIpV61, 500);
            Assert.Equal(ep.ToString(), String.Format("[{0}]:500", ep.Address.ToString()));

            ep = new IPEndPoint(testIpV42, 500);
            Assert.Equal(ep.ToString(), String.Format("{0}:500", ep.Address.ToString()));
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:IPEndPointTest.cs

示例9: Main

    public static void Main()
    {
        IPAddress test = IPAddress.Parse("192.168.1.1");
        Console.WriteLine(test);

        test = IPAddress.Loopback;
        Console.WriteLine(test);

        test = IPAddress.Broadcast;
        Console.WriteLine(test);

        test = IPAddress.Any;
        Console.WriteLine(test);

        test = IPAddress.None;
        Console.WriteLine(test);

        if (IPAddress.IsLoopback(test))
            Console.WriteLine("The Loopback address is: {0}", test.ToString());
        else
            Console.WriteLine("Error obtaining the loopback address");

        test = IPAddress.Parse("192.168.1.1");
        IPEndPoint ie = new IPEndPoint(test, 8000);

        Console.WriteLine("The IPEndPoint is: {0}", ie.ToString());
        Console.WriteLine("The AddressFamily is: {0}", ie.AddressFamily);
        Console.WriteLine("The address is: {0}, and the port is: {1}", ie.Address, ie.Port);

        short test1 = 45;
        int test2 = 314159;
        long test3 = -123456789033452;
        byte[] data = new byte[1024];
        string output;

        short test1b = IPAddress.HostToNetworkOrder(test1);
        data = BitConverter.GetBytes(test1b);
        output = BitConverter.ToString(data);
        Console.WriteLine("test1 = {0}, nbo = {1}", test1b, output);

        int test2b = IPAddress.HostToNetworkOrder(test2);
        data = BitConverter.GetBytes(test2b);
        output = BitConverter.ToString(data);
        Console.WriteLine("test2 = {0}, nbo = {1}", test2b, output);

        long test3b = IPAddress.HostToNetworkOrder(test3);
        data = BitConverter.GetBytes(test3b);
        output = BitConverter.ToString(data);
        Console.WriteLine("test3 = {0}, nbo = {1}", test3b, output);

        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }
开发者ID:dbremner,项目名称:hycs,代码行数:53,代码来源:ipaddr.cs

示例10: FailedToConnect

 private void FailedToConnect(IPEndPoint endpoint)
 {
     string epString = endpoint.ToString();
     if (PeerAddresses.Contains(epString))
     {
         int index = PeerAddresses.IndexOf(epString);
         if (index + 1 == PeerAddresses.Count) return;
         index++;
         socket.ConnectToPeer(PeerAddresses[index]);
     }
     else if (socket.Address == endpoint.Address.ToString() && socket.Port - endpoint.Port > 1)
     {
         if (endpoint.Port == ServerPortRoot) return;
         socket.ConnectToPeer(ServerAddress + ":" + (endpoint.Port - 1));
     }
     else Debug.LogError("Failed to connect to peer(s).");
 }
开发者ID:fredrickvaughn,项目名称:Base,代码行数:17,代码来源:Server.cs

示例11: Run

	static int Run (IPEndPoint ep)
	{
		string url = "http://" + ep.ToString () + "/test/";

		using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) {
			HttpWebRequest req;
			Stream rs;

			req = (HttpWebRequest) WebRequest.Create (url);
			req.Method = "POST";
			req.ContentLength = 2;
			rs = req.GetRequestStream ();
			rs.WriteByte (0x0d);
			try {
				rs.Close ();
				return 1;
			} catch (WebException) {
			}

			req = (HttpWebRequest) WebRequest.Create (url);
			req.Method = "POST";
			req.ContentLength = 2;
			rs = req.GetRequestStream ();
			rs.WriteByte (0x0d);
			try {
				rs.Close ();
				return 2;
			} catch (WebException) {
			}

			req = (HttpWebRequest) WebRequest.Create (url);
			req.Method = "POST";
			req.ContentLength = 2;
			rs = req.GetRequestStream ();
			rs.WriteByte (0x0d);
			rs.WriteByte (0x0d);
			rs.Close ();
			req.Abort ();

			responder.Stop ();
		}

		return 0;
	}
开发者ID:mono,项目名称:gert,代码行数:44,代码来源:test.cs

示例12: Main

    public static int Main()
    {
        bool done = false;
        Console.Write("Enter a port number: ");
        string userInput = Console.ReadLine();
        Int32.TryParse(userInput, out listenPort);
        try
        {
            UdpClient listener = new UdpClient(listenPort);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);

            string received_data;
            byte[] receive_byte_array;
            try
            {

                while (!done)
                {

                    Console.Write("\n\nYou are listening for udp messages on port number " + listenPort + "\n\n");
                    Console.WriteLine("Waiting for broadcast");
                    // this is the line of code that receives the broadcase message.
                    // It calls the receive function from the object listener (class UdpClient)
                    // It passes to listener the end point groupEP.
                    // It puts the data from the broadcast message into the byte array
                    // named received_byte_array.
                    // I don't know why this uses the class UdpClient and IPEndPoint like this.
                    // Contrast this with the talker code. It does not pass by reference.
                    // Note that this is a synchronous or blocking call.
                    receive_byte_array = listener.Receive(ref groupEP);
                    Console.WriteLine("Received a broadcast from {0}", groupEP.ToString());
                    received_data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);
                    switch (received_data)
                    {
                        case "do"        : keybd_event((byte)Keys.VolumeDown, 0, 0, 0);
                                           break;// decrease volume
                        case "up"        : keybd_event((byte)Keys.VolumeUp, 0, 0, 0);
                                           break; // increase volume
                        case "mu"        : keybd_event((byte)Keys.VolumeMute, 0, 0, 0);
                                           break; // mute volume
                        case "off"       : Process.Start("shutdown", "/s /t 0 /f");
                                           break;// pause
                        case "sleep"     : SetSuspendState(false, true, true);
                                           break;
                        case "hibermate" : SetSuspendState(true, true, true);
                                           break;
                        default: break;
                    }
                    Console.WriteLine("data follows \n{0}\n\n", received_data);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            listener.Close();
            return 0;
        }
        catch(Exception e)
        {
            Console.Write("\n" +e.Message);
            Console.Write("\n\n" + e.InnerException);
            Console.Write("\n\nYou selected a port that don't exist or a port that is being used.\nPlease try a higher port number. You can select any value from 0-65535");
            Console.ReadLine();
        }
        return 0;
    }
开发者ID:Daron-Rice,项目名称:SideProjects,代码行数:67,代码来源:Program.cs

示例13: send

 public void send(byte[] data, int size, IPEndPoint endpoint)
 {
     Debug.Log(" >>>Se envia  "  + data.Length + " Bytes  a "  + endpoint.ToString());
     UDPClient.Send(data, size, endpoint);
 }
开发者ID:CristianCosta,项目名称:Kinect,代码行数:5,代码来源:UDPMediaClient.cs

示例14: Main

	// Main entry point.
	public static int Main(String[] args)
			{
				Uri uri;

				// Process the command-line options.
				if(args.Length != 1)
				{
				#if CONFIG_SMALL_CONSOLE
					Console.WriteLine("Usage: sslfetch url");
				#else
					Console.Error.WriteLine("Usage: sslfetch url");
				#endif
					return 1;
				}
				uri = new Uri(args[0]);
				if(uri.Scheme != "https")
				{
				#if CONFIG_SMALL_CONSOLE
					Console.WriteLine("{0} is not a https url", args[0]);
				#else
					Console.Error.WriteLine("{0} is not a https url", args[0]);
				#endif
					return 1;
				}

				// Resolve the hostname and build an end point.
				IPHostEntry entry = Dns.Resolve(uri.Host);
				IPEndPoint ep = new IPEndPoint(entry.AddressList[0], uri.Port);

				// Connect to the remote server.
			#if CONFIG_SMALL_CONSOLE
				Console.WriteLine("Connecting to {0} ...", ep.ToString());
			#else
				Console.Error.WriteLine("Connecting to {0} ...", ep.ToString());
			#endif
				Socket socket = new Socket(AddressFamily.InterNetwork,
										   SocketType.Stream,
										   ProtocolType.Unspecified);
				socket.Connect(ep);

				// Wrap the socket in an SSL client session.
				ISecureSessionProvider provider;
				ISecureSession session;
				provider = SessionProviderFactory.GetProvider();
				session = provider.CreateClientSession(Protocol.AutoDetect);

				// Perform the SSL handshake and get the stream.
			#if CONFIG_SMALL_CONSOLE
				Console.WriteLine("Performing the SSL handshake ...");
			#else
				Console.Error.WriteLine("Performing the SSL handshake ...");
			#endif
				Stream stream = session.PerformHandshake(socket);

				// Write the HTTP "GET" to the server.
			#if CONFIG_SMALL_CONSOLE
				Console.WriteLine("Sending HTTP request ...");
			#else
				Console.Error.WriteLine("Sending HTTP request ...");
			#endif
				String get = "GET " + uri.LocalPath + " HTTP/1.0\r\n";
				get += "\r\n";
				byte[] getData = Encoding.UTF8.GetBytes(get);
				stream.Write(getData, 0, getData.Length);
				stream.Flush();

				// Dump the response.
				byte[] buf = new byte [512];
				char[] cbuf = new char [2048];
				int size;
				while((size = stream.Read(buf, 0, buf.Length)) > 0)
				{
					size = Encoding.UTF8.GetChars(buf, 0, size, cbuf, 0);
					Console.Write(cbuf, 0, size);
				}

				// Close the secure stream.
			#if CONFIG_SMALL_CONSOLE
				Console.WriteLine("Closing the secure session ...");
			#else
				Console.Error.WriteLine("Closing the secure session ...");
			#endif
				stream.Close();
				session.Dispose();

				// Close the socket.
			#if CONFIG_SMALL_CONSOLE
				Console.WriteLine("Closing the underlying socket ...");
			#else
				Console.Error.WriteLine("Closing the underlying socket ...");
			#endif
				socket.Close();

				// Done.
				return 0;
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:97,代码来源:sslfetch.cs

示例15: NetworkStart

 public void NetworkStart()
 {
     IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
         IPAddress ipAddr = ipHost.AddressList[0];
         ipMyPoint = new IPEndPoint(ipAddr, 1100);
         MessageServiceClass.MessageProcessing ("Host Name "+Dns.GetHostName().ToString());
         MessageServiceClass.MessageProcessing (ipMyPoint.ToString());
 }
开发者ID:R---K,项目名称:SQ,代码行数:8,代码来源:NetworkManagerScript.cs


注:本文中的IPEndPoint.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。