本文整理汇总了C#中Lidgren.Network.NetClient.CreateBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.CreateBuffer方法的具体用法?C# NetClient.CreateBuffer怎么用?C# NetClient.CreateBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.CreateBuffer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
s_mainForm = new Form1();
NetConfiguration config = new NetConfiguration("stress");
config.ThrottleBytesPerSecond = 3500;
s_client = new NetClient(config);
// 100 ms simulated roundtrip latency
s_client.SimulatedMinimumLatency = 0.1f;
// ... + 0 to 50 ms
s_client.SimulatedLatencyVariance = 0.05f;
// 10% loss (!)
// s_client.SimulatedLoss = 0.1f;
// 5% duplicated messages (!)
// s_client.SimulatedDuplicates = 0.05f;
s_readBuffer = s_client.CreateBuffer();
s_sentUntil = NetTime.Now;
s_nextDisplay = NetTime.Now;
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(s_mainForm);
s_client.Shutdown("Application exiting");
}
示例2: TankAClient
public TankAClient()
{
NetConfiguration netConfig = new NetConfiguration("TankA");
client = new NetClient(netConfig);
readBuffer = client.CreateBuffer();
timeBetweenFireReq = Tank.MinTBF - 50;
clientIndex = 1;
}
示例3: 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());
}
示例4: ImageClient
public ImageClient()
{
InitializeComponent();
NetConfiguration config = new NetConfiguration("imageservice");
m_client = new NetClient(config);
m_client.SimulatedMinimumLatency = 0.05f;
m_readBuffer = m_client.CreateBuffer();
m_client.DiscoverLocalServers(14242);
this.FormClosed += new FormClosedEventHandler(OnClosed);
this.Show();
}
示例5: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
s_mainForm = new Form1();
NetConfiguration config = new NetConfiguration("OoBSample");
s_client = new NetClient(config);
s_client.SetMessageTypeEnabled(NetMessageType.OutOfBandData, true);
s_client.Start();
s_readBuffer = s_client.CreateBuffer();
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(s_mainForm);
s_client.Shutdown("Bye");
}
示例6: Main
//.........这里部分代码省略.........
int[] bits = new int[24];
for (int i = 0; i < 24; i++)
{
rnd[i] = (byte)NetRandom.Instance.Next(0, 65);
bits[i] = NetUtility.BitsToHoldUInt((uint)rnd[i]);
small.Write(rnd[i], bits[i]);
}
small.Position = 0;
for (int i = 0; i < 24; i++)
{
byte got = small.ReadByte(bits[i]);
if (got != rnd[i])
throw new Exception("Failed small allocation test");
}
double timeEnd = NetTime.Now;
double timeSpan = timeEnd - timeStart;
Console.WriteLine("Trivial tests passed in " + (timeSpan * 1000.0) + " milliseconds");
Console.WriteLine("Creating client and server for live testing...");
NetConfiguration config = new NetConfiguration("unittest");
config.Port = 14242;
NetServer server = new NetServer(config);
NetBuffer serverBuffer = new NetBuffer();
server.Start();
config = new NetConfiguration("unittest");
NetClient client = new NetClient(config);
client.SetMessageTypeEnabled(NetMessageType.Receipt, true);
NetBuffer clientBuffer = client.CreateBuffer();
client.Start();
client.Connect("127.0.0.1", 14242);
List<string> events = new List<string>();
double end = double.MaxValue;
double disconnect = double.MaxValue;
while (NetTime.Now < end)
{
double now = NetTime.Now;
NetMessageType nmt;
NetConnection sender;
//
// client
//
if (client.ReadMessage(clientBuffer, out nmt))
{
switch (nmt)
{
case NetMessageType.StatusChanged:
Console.WriteLine("Client: " + client.Status + " (" + clientBuffer.ReadString() + ")");
events.Add("CStatus " + client.Status);
if (client.Status == NetConnectionStatus.Connected)
{
// send reliable message
NetBuffer buf = client.CreateBuffer();
buf.Write(true);
buf.Write((int)52, 7);
示例7: Main
static void Main(string[] args)
{
NetConfiguration config = new NetConfiguration("durable");
NetClient client = new NetClient(config);
client.SimulatedMinimumLatency = 0.05f;
client.SimulatedLatencyVariance = 0.025f;
client.SimulatedLoss = 0.03f;
// wait half a second to allow server to start up in Visual Studio
Thread.Sleep(500);
// create a buffer to read data into
NetBuffer buffer = client.CreateBuffer();
// connect to localhost
client.Connect("localhost", 14242, Encoding.ASCII.GetBytes("Hail from client"));
// enable some library messages
client.SetMessageTypeEnabled(NetMessageType.BadMessageReceived, true);
//client.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
client.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
FileStream fs = new FileStream("./clientlog.txt", FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter wrt = new StreamWriter(fs);
Output(wrt, "Log started at " + DateTime.Now);
wrt.Flush();
// create a stopwatch
Stopwatch sw = new Stopwatch();
sw.Start();
int loops = 0;
while (!Console.KeyAvailable)
{
NetMessageType type;
if (client.ReadMessage(buffer, out type))
{
switch (type)
{
case NetMessageType.StatusChanged:
if (client.ServerConnection.RemoteHailData != null)
Output(wrt, "New status: " + client.Status + " (" + buffer.ReadString() + ") Remote hail is: " + Encoding.ASCII.GetString(client.ServerConnection.RemoteHailData));
else
Output(wrt, "New status: " + client.Status + " (" + buffer.ReadString() + ") Remote hail hasn't arrived.");
break;
case NetMessageType.BadMessageReceived:
case NetMessageType.ConnectionRejected:
case NetMessageType.DebugMessage:
case NetMessageType.VerboseDebugMessage:
//
// These types of messages all contain a string in the buffer; display it.
//
Output(wrt, buffer.ReadString());
break;
case NetMessageType.Data:
default:
//
// For this application; server doesn't send any data... so Data messages are unhandled
//
Output(wrt, "Unhandled: " + type + " " + buffer.ToString());
break;
}
}
// send a message every second
if (client.Status == NetConnectionStatus.Connected && sw.Elapsed.TotalMilliseconds >= 516)
{
loops++;
//Console.WriteLine("Sending message #" + loops);
Console.Title = "Client; Messages sent: " + loops;
Output(wrt, "Sending #" + loops + " at " + NetTime.ToMillis(NetTime.Now));
NetBuffer send = client.CreateBuffer();
send.Write("Message #" + loops);
client.SendMessage(send, NetChannel.ReliableInOrder14);
sw.Reset();
sw.Start();
}
Thread.Sleep(1);
}
// clean shutdown
client.Shutdown("Application exiting");
wrt.Close();
}
示例8: Run
protected virtual void Run()
{
connected = false;
client = new NetClient(netConfig);
client.Connect(host, port, Encoding.ASCII.GetBytes("Hail"));
client.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
#if DEBUG
client.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
#endif
buffer = client.CreateBuffer();
while (true)
{
CheckUpdates();
Thread.Sleep(1);
}
}