本文整理汇总了C#中Lidgren.Network.NetServer.CreateBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# NetServer.CreateBuffer方法的具体用法?C# NetServer.CreateBuffer怎么用?C# NetServer.CreateBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetServer
的用法示例。
在下文中一共展示了NetServer.CreateBuffer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public static void Process(NetServer server, NetBuffer buffer, NetConnection sender)
{
Config config = Config.Instance;
List<NetConnection> connections = server.Connections;
//Lets send that message onto any plugin clients
foreach (NetConnection connection in connections)
{
if (config.Server.client_connections.ContainsKey(connection.RemoteEndpoint.ToString()))
{
string client_type = (string)config.Server.client_connections[connection.RemoteEndpoint.ToString()];
if (client_type.ToLower() == "plugin")
{
string msg = buffer.ReadString();
Console.WriteLine("Slave: Data sent - " + msg);
NetBuffer slavebuf = server.CreateBuffer();
slavebuf.Write(msg);
server.SendMessage(slavebuf, connection, NetChannel.ReliableInOrder4);
}
}
}
}
示例2: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
s_mainForm = new Form1();
NetConfiguration config = new NetConfiguration("OoBSample");
config.MaxConnections = 0; // we accept only OoB data
config.Port = 14242;
s_server = new NetServer(config);
s_server.SetMessageTypeEnabled(NetMessageType.OutOfBandData, true);
s_server.Start();
s_readBuffer = s_server.CreateBuffer();
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(s_mainForm);
s_server.Shutdown("Bye");
}
示例3: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
s_mainForm = new Form1();
NetConfiguration config = new NetConfiguration("stress");
config.Port = 14242;
config.MaxConnections = 32;
s_server = new NetServer(config);
s_server.SimulatedMinimumLatency = 0.1f;
s_server.SimulatedLatencyVariance = 0.05f;
// s_server.SimulatedLoss = 0.1f;
// s_server.SimulatedDuplicates = 0.05f;
s_readBuffer = s_server.CreateBuffer();
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(s_mainForm);
s_server.Shutdown("Application exiting");
}
示例4: Run
protected virtual void Run()
{
// create server and start listening for connections
server = new NetServer(netConfig);
server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
server.Start();
buffer = server.CreateBuffer();
while (true)
{
CheckUpdates();
Thread.Sleep(1);
}
}
示例5: Main
static void Main(string[] args)
{
NetConfiguration config = new NetConfiguration("durable");
config.MaxConnections = 128;
config.Port = 14242;
NetServer server = new NetServer(config);
server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
server.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
//server.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
server.SetMessageTypeEnabled(NetMessageType.StatusChanged, true);
server.SimulatedMinimumLatency = 0.05f;
server.SimulatedLatencyVariance = 0.025f;
server.SimulatedLoss = 0.03f;
server.Start();
FileStream fs = new FileStream("./serverlog.txt", FileMode.Create, FileAccess.Write, FileShare.Read);
StreamWriter wrt = new StreamWriter(fs);
Output(wrt, "Log started at " + DateTime.Now);
wrt.Flush();
NetBuffer buffer = server.CreateBuffer();
int expected = 1;
Console.WriteLine("Press any key to quit");
while (!Console.KeyAvailable)
{
NetMessageType type;
NetConnection sender;
if (server.ReadMessage(buffer, out type, out sender))
{
switch (type)
{
case NetMessageType.StatusChanged:
if (sender.RemoteHailData != null)
Output(wrt, "New status: " + sender.Status + " (" + buffer.ReadString() + ") Remote hail is: " + Encoding.ASCII.GetString(sender.RemoteHailData));
else
Output(wrt, "New status: " + sender.Status + " (" + buffer.ReadString() + ") Remote hail hasn't arrived.");
break;
case NetMessageType.BadMessageReceived:
case NetMessageType.ConnectionRejected:
case NetMessageType.DebugMessage:
//
// All these types of messages all contain a single string in the buffer; display it
//
Output(wrt, buffer.ReadString());
break;
case NetMessageType.VerboseDebugMessage:
wrt.WriteLine(buffer.ReadString()); // don't output to console
break;
case NetMessageType.ConnectionApproval:
if (sender.RemoteHailData != null &&
Encoding.ASCII.GetString(sender.RemoteHailData) == "Hail from client")
{
Output(wrt, "Hail ok!");
sender.Approve(Encoding.ASCII.GetBytes("Hail from server"));
}
else
{
sender.Disapprove("Wrong hail!");
}
break;
case NetMessageType.Data:
string str = buffer.ReadString();
// parse it
int nr = Int32.Parse(str.Substring(9));
if (nr != expected)
{
Output(wrt, "Warning! Expected " + expected + "; received " + nr + " str is ---" + str + "---");
}
else
{
expected++;
Console.Title = "Server; received " + nr + " messages";
}
break;
default:
Output(wrt, "Unhandled: " + type + " " + buffer.ToString());
break;
}
}
Thread.Sleep(1);
}
// clean shutdown
wrt.Close();
server.Shutdown("Application exiting");
}
示例6: StartServer
private static void StartServer()
{
// create a configuration for the server
NetConfiguration config = new NetConfiguration("EES");
config.MaxConnections = 128;
config.Port = 14242;
// create server and start listening for connections
NetServer server = new NetServer(config);
server.SetMessageTypeEnabled(NetMessageType.DebugMessage, false);
server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
server.Start();
// create a buffer to read data into
NetBuffer buffer = server.CreateBuffer();
// keep running until the user presses a key
Console.WriteLine("Press ESC to quit server");
bool keepRunning = true;
while (keepRunning)
{
NetMessageType type;
NetConnection sender;
// check if any messages has been received
while (server.ReadMessage(buffer, out type, out sender))
{
switch (type)
{
case NetMessageType.DebugMessage:
netevent.fireDebugMessage(buffer.ReadString());
break;
case NetMessageType.ConnectionApproval:
netevent.fireClientApproval(server, buffer, sender);
break;
case NetMessageType.StatusChanged:
netevent.fireStatusChanged(server, buffer, sender);
break;
case NetMessageType.Data:
netevent.fireDataRecieved(server, buffer, sender);
break;
}
}
// User pressed ESC?
while (Console.KeyAvailable)
{
ConsoleKeyInfo info = Console.ReadKey();
if (info.Key == ConsoleKey.Escape)
{
keepRunning = false;
}
else if (info.Key == ConsoleKey.I)
{
//Create line
Console.WriteLine("");
//Get config
Config server_config = Config.Instance;
foreach (DictionaryEntry entry in server_config.Server.client_connections)
{
Console.WriteLine("Client: '" + entry.Value + "' from: " + entry.Key);
}
}
}
Thread.Sleep(1);
}
server.Shutdown("Server exiting");
}
示例7: TankAHost
public TankAHost(GameLogicMode hostMode)
{
NetConfiguration netConfig = new NetConfiguration("TankA");
netConfig.MaxConnections = 10;
netConfig.Port = NetworkManager.Port;
host = new NetServer(netConfig);
readBuffer = host.CreateBuffer();
currentFrame = framePerUpdate;
this.hostMode = hostMode;
}