本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadIPEndPoint方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadIPEndPoint方法的具体用法?C# NetBuffer.ReadIPEndPoint怎么用?C# NetBuffer.ReadIPEndPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadIPEndPoint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
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: ServerDiscoveredHandler
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: HandleMessage
/// <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: ServerInformation
public ServerInformation(NetBuffer netBuffer)
{
ipEndPoint = netBuffer.ReadIPEndPoint();
serverName = ipEndPoint.Address.ToString();
lanServer = true;
}