本文整理汇总了C#中RakNet.BitStream.Write方法的典型用法代码示例。如果您正苦于以下问题:C# BitStream.Write方法的具体用法?C# BitStream.Write怎么用?C# BitStream.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RakNet.BitStream
的用法示例。
在下文中一共展示了BitStream.Write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _SendUnitData
static void _SendUnitData (){
FT_UnitData data = new FT_UnitData();
BitStream writeBitStream = new BitStream();
writeBitStream.Write((byte)FT_MessageTypes.ID_SERVER_LOGIN);
writeBitStream.Write((byte)FT_MessageTypesNode.NODE_FT_TEST1);
data.Serialize(true, writeBitStream);
client.Send(writeBitStream, (char)0);
}
示例2: Main
static void Main(string[] args)
{
if (!File.Exists("RakNet.dll"))
{
Console.WriteLine("The SWIG build of the DLL has not been copied to the executable directory\nCopy from Swig/SwigWindowsCSharpSample/SwigTestApp/bin/X86/Debug/RakNet.dll to\nSwigWindowsCSharpSample/SwigTestApp/bin/Debug/RakNet.dll\nPress enter to quit.");
Console.Read();
return;
}
try
{
RakString dllCallTest = new RakString();
}
catch (Exception e)
{
Console.WriteLine("DLL issue\nAdd SwigOutput/CplusDLLIncludes/RakNetWrap.cxx to the project\nDLL_Swig/RakNet.sln and rebuild.\nPress enter to quit.");
Console.Read();
return;
}
Packet testPacket;
int loopNumber;
BitStream stringTestSendBitStream = new BitStream();
BitStream rakStringTestSendBitStream = new BitStream();
BitStream receiveBitStream = new BitStream();
String holdingString;
TimeSpan startTimeSpan;
RakString rakStringTest = new RakString();
RakPeerInterface testClient = RakPeer.GetInstance();
testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);
RakPeerInterface testServer = RakPeer.GetInstance();
testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
testServer.SetMaximumIncomingConnections(1);
Console.WriteLine("Send and receive loop using BitStream.\nBitStream read done into RakString");
testClient.Connect("127.0.0.1", 60001, "", 0);
String sendString = "The test string";
stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
stringTestSendBitStream.Write(sendString);
RakString testRakString = new RakString("Test RakString");
rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
rakStringTestSendBitStream.Write(testRakString);
startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
loopNumber = 0;
while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
{
testPacket = testServer.Receive();
if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
receiveBitStream.Reset();
receiveBitStream.Write(testPacket.data, testPacket.length);
receiveBitStream.IgnoreBytes(1);
receiveBitStream.Read(rakStringTest);
Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
}
testServer.DeallocatePacket(testPacket);
loopNumber++;
System.Threading.Thread.Sleep(50);
testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
}
Console.WriteLine("String send and receive loop using BitStream.\nBitStream read done into String");
SystemAddress[] remoteSystems;
ushort numberOfSystems=1;
testServer.GetConnectionList(out remoteSystems, ref numberOfSystems);
startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
loopNumber = 0;
while (startTimeSpan.TotalSeconds + 5 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
{
testPacket = testServer.Receive();
if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
receiveBitStream.Reset();
receiveBitStream.Write(testPacket.data, testPacket.length);
receiveBitStream.IgnoreBytes(1);
receiveBitStream.Read(out holdingString);
Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
}
testServer.DeallocatePacket(testPacket);
loopNumber++;
System.Threading.Thread.Sleep(50);
SystemAddress sa = RakNet.RakNet.UNASSIGNED_SYSTEM_ADDRESS;
testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
}
//If RakString is not freed before program exit it will crash
rakStringTest.Dispose();
testRakString.Dispose();
RakPeer.DestroyInstance(testClient);
RakPeer.DestroyInstance(testServer);
//.........这里部分代码省略.........
示例3: Main
static void Main(string[] args)
{
if(!File.Exists("RakNet.dll"))
{
Console.WriteLine("Error: The SWIG build of the DLL has not been copied to the executable directory.\nPress enter.");
Console.Read();
return;
}
Packet testPacket;
int loopNumber;
BitStream stringTestSendBitStream = new BitStream();
BitStream rakStringTestSendBitStream = new BitStream();
BitStream receiveBitStream = new BitStream();
String holdingString;
TimeSpan startTimeSpan;
RakString rakStringTest = new RakString();
RakPeerInterface testClient = RakPeer.GetInstance();
testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);
RakPeerInterface testServer = RakPeer.GetInstance();
testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
testServer.SetMaximumIncomingConnections(1);
Console.WriteLine("Press enter to start RakString send and receive loop using BitStream.\nBitStream read done into RakString");
Console.WriteLine("Loop will run for 15 seconds");
Console.ReadLine();
testClient.Connect("127.0.0.1", 60001, "", 0);
String sendString = "The test string";
stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
stringTestSendBitStream.Write(sendString);
RakString testRakString = new RakString("Test RakString");
rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
rakStringTestSendBitStream.Write(testRakString);
startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
loopNumber = 0;
while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
{
testPacket = testServer.Receive();
if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
receiveBitStream.Reset();
receiveBitStream.Write(testPacket.data, testPacket.length);
receiveBitStream.IgnoreBytes(1);
receiveBitStream.Read(rakStringTest);
Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
}
testServer.DeallocatePacket(testPacket);
loopNumber++;
System.Threading.Thread.Sleep(50);
testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
}
Console.WriteLine("Press enter to start String send and receive loop using BitStream.\nBitStream read done into String");
Console.WriteLine("Loop will run for 15 seconds");
Console.ReadLine();
startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
loopNumber = 0;
while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
{
testPacket = testServer.Receive();
if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
receiveBitStream.Reset();
receiveBitStream.Write(testPacket.data, testPacket.length);
receiveBitStream.IgnoreBytes(1);
receiveBitStream.Read(out holdingString);
Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
}
testServer.DeallocatePacket(testPacket);
loopNumber++;
System.Threading.Thread.Sleep(50);
testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
}
//-----------------------------Above is the same as the public tests, below the internal tests are ran.
/*Member variables are also tested to assure working typemaps
* Also variables use functions as well, they are not direct access
* act like it. Test write and read on these items, especially arrays.
* Most tests in this section are simple running functions with no verification.
*
*
*/
RakString workingRakStringCopy;//This is needed for temp RakString Instances in the main function so dispose can be called
//RakNetStatistics
Console.WriteLine("RakNetStatistics");
string rakNetStatisticsTestString;
RakNetStatistics testRakNetStatistics = new RakNetStatistics();
testRakNetStatistics.bytesInSendBuffer[0] = 22.44;
testRakNetStatistics.BPSLimitByCongestionControl = 9;
testRakNetStatistics.BPSLimitByOutgoingBandwidthLimit = 9;
testRakNetStatistics.connectionStartTime = 9;
//.........这里部分代码省略.........
示例4: ProcessMessage
static void ProcessMessage(RakPeerInterface peer, RakNet.Packet packet)
{
if (packet != null)
{
if (packet.data[0] == (byte)(FT_MessageTypes.ID_SERVER_LOGIN))
{
BitStream receiveBitStream = new BitStream();
receiveBitStream.Write(packet.data, packet.length);
receiveBitStream.IgnoreBytes(2);
FT_UnitData data = new FT_UnitData();
data.Serialize(false, receiveBitStream);
Log.Debug(" data.nGrid_x: " + data.nGrid_x);
BitStream writeBitStream = new BitStream();
writeBitStream.Write((byte)FT_MessageTypes.ID_SERVER_LOGIN);
writeBitStream.Write((byte)FT_MessageTypesNode.NODE_FT_TEST1);
data.Serialize(true, writeBitStream);
uint sendLength = peer.Send(writeBitStream, PacketPriority.HIGH_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, packet.systemAddress, false);
Log.Debug("SendLength = " + sendLength);
}
}
}
示例5: Main
static void Main(string[] args)
{
Packet testPacket;
int loopNumber;
BitStream stringTestSendBitStream = new BitStream();
BitStream rakStringTestSendBitStream = new BitStream();
BitStream receiveBitStream = new BitStream();
String holdingString;
TimeSpan startTimeSpan;
RakString rakStringTest = new RakString();
RakPeerInterface testClient = RakPeer.GetInstance();
testClient.Startup(1, new SocketDescriptor(60000, "127.0.0.1"), 1);
RakPeerInterface testServer = RakPeer.GetInstance();
testServer.Startup(1, new SocketDescriptor(60001, "127.0.0.1"), 1);
testServer.SetMaximumIncomingConnections(1);
Console.WriteLine("Press enter to start RakString send and receive loop using BitStream.\nBitStream read done into RakString");
Console.WriteLine("Loop will run for 15 seconds");
Console.ReadLine();
testClient.Connect("127.0.0.1", 60001, "", 0);
String sendString = "The test string";
stringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
stringTestSendBitStream.Write(sendString);
RakString testRakString = new RakString("Test RakString");
rakStringTestSendBitStream.Write((byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM);
rakStringTestSendBitStream.Write(testRakString);
startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
loopNumber = 0;
while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
{
testPacket = testServer.Receive();
if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
receiveBitStream.Reset();
receiveBitStream.Write(testPacket.data, testPacket.length);
receiveBitStream.IgnoreBytes(1);
receiveBitStream.Read(rakStringTest);
Console.WriteLine("Loop number: " + loopNumber + "\nData: " + rakStringTest.C_String());
}
testServer.DeallocatePacket(testPacket);
loopNumber++;
System.Threading.Thread.Sleep(50);
testClient.Send(rakStringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
}
Console.WriteLine("Press enter to start String send and receive loop using BitStream.\nBitStream read done into String");
Console.WriteLine("Loop will run for 15 seconds");
Console.ReadLine();
startTimeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1));
loopNumber = 0;
while (startTimeSpan.TotalSeconds + 15 > (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)
{
testPacket = testServer.Receive();
if (testPacket != null && testPacket.data[0] == (byte)DefaultMessageIDTypes.ID_USER_PACKET_ENUM)
{
receiveBitStream.Reset();
receiveBitStream.Write(testPacket.data, testPacket.length);
receiveBitStream.IgnoreBytes(1);
receiveBitStream.Read(out holdingString);
Console.WriteLine("Loop number: " + loopNumber + "\nData: " + holdingString);
}
testServer.DeallocatePacket(testPacket);
loopNumber++;
System.Threading.Thread.Sleep(50);
testClient.Send(stringTestSendBitStream, PacketPriority.LOW_PRIORITY, PacketReliability.RELIABLE_ORDERED, (char)0, new AddressOrGUID(new SystemAddress("127.0.0.1", 60001)), false);
}
//If RakString is not freed before program exit it will crash
rakStringTest.Dispose();
testRakString.Dispose();
RakPeer.DestroyInstance(testClient);
RakPeer.DestroyInstance(testServer);
Console.WriteLine("Demo complete. Press Enter.");
Console.Read();
}