ReadIPEndPoint() публичный Метод

Reads a stored IPv4 endpoint description
public ReadIPEndPoint ( ) : IPEndPoint
Результат System.Net.IPEndPoint
Пример #1
0
		private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
		{
			switch (type)
			{
				case NetMessageType.StatusChanged:
					if (source.LocalHailData == null)
						source.LocalHailData = Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode());
					if (source.RemoteHailData != null)
						WriteToConsole("New status: " + source.Status + " - remote hail is: " + Encoding.ASCII.GetString(source.RemoteHailData));
					else
						WriteToConsole("New status: " + source.Status + " - remote hail is null");
					break;
				case NetMessageType.DebugMessage:
				case NetMessageType.VerboseDebugMessage:
				case NetMessageType.BadMessageReceived:
				case NetMessageType.ConnectionRejected:
					WriteToConsole(buffer.ReadString());
					break;
				case NetMessageType.Data:
					WriteToConsole(source.RemoteEndpoint + " writes: " + buffer.ReadString());
					break;
				case NetMessageType.ServerDiscovered:
					// discovered another peer!
					s_peer.Connect(buffer.ReadIPEndPoint(), Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode()));
					break;
				default:
					// unhandled
					break;
			}
		}
Пример #2
0
        public static void ServerDiscoveredHandler(NetClient client, NetBuffer buffer)
        {
            System.Net.IPEndPoint buffer_copier = buffer.ReadIPEndPoint();

            //Just connect to the first server we find
            Console.WriteLine("Client: Connecting to server: " + buffer_copier.ToString());

            //Let server know the type of IOS client connecting
            NetBuffer buf = client.CreateBuffer();
            buf.Write("Slave");

            //Connect
            client.Connect(buffer_copier, buf.ToArray());
        }
Пример #3
0
		/// <summary>
		/// Handle incoming message
		/// </summary>
		private void HandleMessage(NetMessageType type, NetBuffer buffer)
		{
			switch (type)
			{
				case NetMessageType.DebugMessage:
					//
					// it's a library debug message; just display it in the console if debugger is attached
					//
					Console.WriteLine(buffer.ReadString());
					break;
				case NetMessageType.StatusChanged:
					//
					// it's a status change message; set the reason as window title and refresh picture
					//
					this.Text = buffer.ReadString();
					pictureBox1.Refresh();
					break;
				case NetMessageType.ServerDiscovered:
					//
					// it's a server discovered message; connect to the discovered server
					//
					m_imageWidth = 0;
					m_imageHeight = 0;
					m_lineDisplayed = 0;

					m_client.Connect(buffer.ReadIPEndPoint());
					break;
				case NetMessageType.Data:
					//
					// it's a data message (data sent from the server)
					//
					if (m_imageWidth == 0)
					{
						// first message is size
						m_imageWidth = (int)buffer.ReadVariableUInt32();
						m_imageHeight = (int)buffer.ReadVariableUInt32();
						this.Size = new System.Drawing.Size(m_imageWidth + 40, m_imageHeight + 60);
						pictureBox1.Image = new Bitmap(m_imageWidth, m_imageHeight);
						pictureBox1.SetBounds(12, 12, m_imageWidth, m_imageHeight);
						return;
					}

					uint pixelPos = buffer.ReadUInt32();

					// it's color data
					int y = (int)(pixelPos / m_imageWidth);
					int x = (int)(pixelPos - (y * m_imageWidth));

					Bitmap bm = pictureBox1.Image as Bitmap;
					pictureBox1.SuspendLayout();
					int pixels = (buffer.LengthBytes - 4) / 3;
					for (int i = 0; i < pixels; i++)
					{
						// set pixel
						byte r = buffer.ReadByte();
						byte g = buffer.ReadByte();
						byte b = buffer.ReadByte();
						Color col = Color.FromArgb(r, g, b);
						if (y > m_imageHeight)
							continue;
						bm.SetPixel(x, y, col);
						x++;
						if (x >= m_imageWidth)
						{
							x = 0;
							y++;
						}
					}
					pictureBox1.ResumeLayout();

					// refresh image every horizontal line
					if (pixelPos / m_imageWidth > m_lineDisplayed)
					{
						m_lineDisplayed = (int)(pixelPos / m_imageWidth);
						pictureBox1.Refresh();
					}
					break;
				default:
					// unhandled
					break;
			}
		}
Пример #4
0
 public ServerInformation(NetBuffer netBuffer)
 {
     ipEndPoint = netBuffer.ReadIPEndPoint();
     serverName = ipEndPoint.Address.ToString();
     lanServer = true;
 }