本文整理汇总了C#中Lidgren.Network.NetServer.SetMessageTypeEnabled方法的典型用法代码示例。如果您正苦于以下问题:C# NetServer.SetMessageTypeEnabled方法的具体用法?C# NetServer.SetMessageTypeEnabled怎么用?C# NetServer.SetMessageTypeEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetServer
的用法示例。
在下文中一共展示了NetServer.SetMessageTypeEnabled方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NetServerWrapper
public NetServerWrapper(NetServer netServer)
{
_netServer = netServer;
//_netServer.Simulate(0.1f, 0.1f, 0.2f, 0.1f);
_netServer.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
#if DEBUG
_netServer.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
#endif
}
示例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: 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);
}
}
示例4: 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");
}
示例5: 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");
}
示例6: OpenIP
void OpenIP()
{
int port = net_port.Integer;
svConfig.MaxConnections = 64;
svConfig.Port = port;
server = new NetServer(svConfig);
server.Configuration.AnswerDiscoveryRequests = false;
server.EnabledMessageTypes |= NetMessageType.OutOfBandData;
//server.SimulatedMinimumLatency = 0.7f;
server.SetMessageTypeEnabled(NetMessageType.ConnectionApproval, true);
try
{
server.Start();
}
catch (NetException ex)
{
// Try the next port
server.Configuration.Port = ++port;
server.Start();
}
client = new NetClient(clConfig);
//client.SimulatedMinimumLatency = 0.2f;
//client.RunSleep = 0;
client.EnabledMessageTypes |= NetMessageType.OutOfBandData;
client.Start();
}