本文整理汇总了C#中Lidgren.Network.NetClient.SetMessageTypeEnabled方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.SetMessageTypeEnabled方法的具体用法?C# NetClient.SetMessageTypeEnabled怎么用?C# NetClient.SetMessageTypeEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.SetMessageTypeEnabled方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NetClientWrapper
public NetClientWrapper(NetClient netClient)
{
_netClient = netClient;
_netClient.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
_netClient.SetMessageTypeEnabled(NetMessageType.BadMessageReceived, true);
//_netClient.Simulate(0.1f, 0.1f, 0.2f, 0.1f);
#if DEBUG
_netClient.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
_netClient.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
#endif
}
示例2: 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");
}
示例3: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
m_mainForm = new Form1();
NetConfiguration config = new NetConfiguration("largepacket");
config.SendBufferSize = 128000;
config.ThrottleBytesPerSecond = 8192;
m_client = new NetClient(config);
m_client.SimulatedLoss = 0.03f; // 3 %
m_client.SimulatedMinimumLatency = 0.1f; // 100 ms
m_client.SimulatedLatencyVariance = 0.05f; // 100-150 ms actually
//m_client.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
m_client.SetMessageTypeEnabled(NetMessageType.Receipt, true);
m_readBuffer = m_client.CreateBuffer();
Application.Idle += new EventHandler(OnAppIdle);
Application.Run(m_mainForm);
m_client.Shutdown("Application exiting");
}
示例4: Main
//.........这里部分代码省略.........
byte[] rnd = new byte[24];
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);
示例5: PropertyBag
bool colorDirection = true; //increases when true
#endregion Fields
#region Constructors
public PropertyBag(InfiniminerGame gameInstance)
{
// Initialize our network device.
NetConfiguration netConfig = new NetConfiguration("InfiniminerPlus");
netClient = new NetClient(netConfig);
netClient.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
//netClient.SimulatedMinimumLatency = 0.5f;
//netClient.SimulatedLatencyVariance = 0.1f;
//netClient.SimulatedLoss = 0.2f;
//netClient.SimulatedDuplicates = 0.1f;
for (int a = 0; a < 50; a++)
{
Content[a] = 0;
}
artifactActive = new int[3, 20];
netClient.Start();
// Initialize engines.
blockEngine = new BlockEngine(gameInstance);
interfaceEngine = new InterfaceEngine(gameInstance);
playerEngine = new PlayerEngine(gameInstance);
skyplaneEngine = new SkyplaneEngine(gameInstance);
particleEngine = new ParticleEngine(gameInstance);
// Create a camera.
playerCamera = new Camera(gameInstance.GraphicsDevice);
UpdateCamera();
// Load sounds.
if (!gameInstance.NoSound)
{
soundList[InfiniminerSound.DigDirt] = gameInstance.Content.Load<SoundEffect>("sounds/dig-dirt");
soundList[InfiniminerSound.DigMetal] = gameInstance.Content.Load<SoundEffect>("sounds/dig-metal");
soundList[InfiniminerSound.Ping] = gameInstance.Content.Load<SoundEffect>("sounds/ping");
soundList[InfiniminerSound.ConstructionGun] = gameInstance.Content.Load<SoundEffect>("sounds/build");
soundList[InfiniminerSound.Death] = gameInstance.Content.Load<SoundEffect>("sounds/death");
soundList[InfiniminerSound.CashDeposit] = gameInstance.Content.Load<SoundEffect>("sounds/cash");
soundList[InfiniminerSound.ClickHigh] = gameInstance.Content.Load<SoundEffect>("sounds/click-loud");
soundList[InfiniminerSound.ClickLow] = gameInstance.Content.Load<SoundEffect>("sounds/click-quiet");
soundList[InfiniminerSound.GroundHit] = gameInstance.Content.Load<SoundEffect>("sounds/hitground");
soundList[InfiniminerSound.Teleporter] = gameInstance.Content.Load<SoundEffect>("sounds/teleport");
soundList[InfiniminerSound.Jumpblock] = gameInstance.Content.Load<SoundEffect>("sounds/jumpblock");
soundList[InfiniminerSound.Explosion] = gameInstance.Content.Load<SoundEffect>("sounds/explosion");
soundList[InfiniminerSound.RadarHigh] = gameInstance.Content.Load<SoundEffect>("sounds/radar-high");
soundList[InfiniminerSound.RadarLow] = gameInstance.Content.Load<SoundEffect>("sounds/radar-low");
soundList[InfiniminerSound.RadarSwitch] = gameInstance.Content.Load<SoundEffect>("sounds/switch");
soundList[InfiniminerSound.RockFall] = gameInstance.Content.Load<SoundEffect>("sounds/rockfall");
}
}
示例6: setupNetwork
public static void setupNetwork()
{
NetConfiguration config = new NetConfiguration("apache");
client = new NetClient(config);
client.SetMessageTypeEnabled(NetMessageType.ConnectionRejected, true);
//client.SetMessageTypeEnabled(NetMessageType.DebugMessage, true);
//client.SetMessageTypeEnabled(NetMessageType.VerboseDebugMessage, true);
client.Start();
// Wait half a second to allow server to start up if run via Visual Studio
Thread.Sleep(500);
// Emit discovery signal
//client.DiscoverLocalServers(14242);
client.Connect("127.0.0.1", 14242, Encoding.ASCII.GetBytes("Hail from client"));
Thread.Sleep(500);
}
示例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);
}
}