本文整理汇总了C#中Msg.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.Write方法的具体用法?C# Msg.Write怎么用?C# Msg.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg.Write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGUI
void OnGUI(){
GUI.TextArea (new Rect (10, 10, 500, 400), show_str);
modelId =GUI.TextField (new Rect (520, 10, 80, 30), modelId);
actionId=GUI.TextField (new Rect (600, 10, 80, 30), actionId);
msg =GUI.TextField (new Rect (520, 50, 160, 30), msg);
if (GUI.Button (new Rect (690, 10, 160, 30), "ADD_STR")) {
}
if (GUI.Button (new Rect (690, 50, 160, 30), "SEND")) {
string str = modelId + "-" + actionId + " data =" + msg;
string statc = "0,0,'538642', '1', '10002', '1', 99000000, 999999";
Msg data = new Msg ();
data.Write (1);
//data.Write ('a');
//data.Write ((byte)1.1f);
//data.Write(11);
data.Write (2L);
byte[] b = data.Buffer;
bool a0 = data.ReadBoolean ();
//char a1 = (char)data.ReadByte ();
long a2 = data.ReadInt64 ();
//float a2 = float.Parse(data.ReadBytes (sizeof(float)));
Debug.Log ("=sum length=="+(sizeof(int)+sizeof(long))+"============byte array===" + data.Length);
Debug.Log ("=======a0=" + a0);
//Debug.Log ("=======a1=" + a1);
Debug.Log ("=======a2=" + a2);
//Debug.Log ("encode code==================="+code);
AppendShowString(str);
}
if (GUI.Button(new Rect(690, 90, 160, 30), "connect")) {
try {
network.connectServer();
AppendShowString("connect to server");
}
catch (Exception e) {
AppendShowString(e.ToString());
}
}
if (GUI.Button(new Rect(690,130,160,30),"disconnect")){
try
{
network.closeConnection();
AppendShowString("disconnect server");
}catch(Exception e)
{
AppendShowString(e.ToString());
}
}
}
示例2: HandleEncryptRequest
void HandleEncryptRequest( IPacketMsg packetMsg )
{
var encRequest = new Msg<MsgChannelEncryptRequest>( packetMsg );
EUniverse eUniv = encRequest.Body.Universe;
uint protoVersion = encRequest.Body.ProtocolVersion;
DebugLog.WriteLine( "CMClient", "Got encryption request. Universe: {0} Protocol ver: {1}", eUniv, protoVersion );
byte[] pubKey = KeyDictionary.GetPublicKey( eUniv );
if ( pubKey == null )
{
DebugLog.WriteLine( "CMClient", "HandleEncryptionRequest got request for invalid universe! Universe: {0} Protocol ver: {1}", eUniv, protoVersion );
return;
}
ConnectedUniverse = eUniv;
var encResp = new Msg<MsgChannelEncryptResponse>();
tempSessionKey = CryptoHelper.GenerateRandomBlock( 32 );
byte[] cryptedSessKey = null;
using ( var rsa = new RSACrypto( pubKey ) )
{
cryptedSessKey = rsa.Encrypt( tempSessionKey );
}
byte[] keyCrc = CryptoHelper.CRCHash( cryptedSessKey );
encResp.Write( cryptedSessKey );
encResp.Write( keyCrc );
encResp.Write( ( uint )0 );
this.Send( encResp );
}
示例3: HandleEncryptRequest
void HandleEncryptRequest( IPacketMsg packetMsg )
{
var encRequest = new Msg<MsgChannelEncryptRequest>( packetMsg );
EUniverse eUniv = encRequest.Body.Universe;
uint protoVersion = encRequest.Body.ProtocolVersion;
DebugLog.WriteLine( "UFSClient", "Got encryption request. Universe: {0} Protocol ver: {1}", eUniv, protoVersion );
DebugLog.Assert( protoVersion == 1, "UFSClient", "Encryption handshake protocol version mismatch!" );
byte[] randomChallenge;
if ( encRequest.Payload.Length >= 16 )
{
randomChallenge = encRequest.Payload.ToArray();
}
else
{
randomChallenge = null;
}
byte[] pubKey = KeyDictionary.GetPublicKey( eUniv );
if ( pubKey == null )
{
connection.Disconnect();
DebugLog.WriteLine( "UFSClient", "HandleEncryptionRequest got request for invalid universe! Universe: {0} Protocol ver: {1}", eUniv, protoVersion );
return;
}
ConnectedUniverse = eUniv;
var encResp = new Msg<MsgChannelEncryptResponse>();
var tempSessionKey = CryptoHelper.GenerateRandomBlock( 32 );
byte[] encryptedHandshakeBlob = null;
using ( var rsa = new RSACrypto( pubKey ) )
{
if ( randomChallenge != null )
{
var blobToEncrypt = new byte[ tempSessionKey.Length + randomChallenge.Length ];
Array.Copy( tempSessionKey, blobToEncrypt, tempSessionKey.Length );
Array.Copy( randomChallenge, 0, blobToEncrypt, tempSessionKey.Length, randomChallenge.Length );
encryptedHandshakeBlob = rsa.Encrypt( blobToEncrypt );
}
else
{
encryptedHandshakeBlob = rsa.Encrypt( tempSessionKey );
}
}
var keyCrc = CryptoHelper.CRCHash( encryptedHandshakeBlob );
encResp.Write( encryptedHandshakeBlob );
encResp.Write( keyCrc );
encResp.Write( ( uint )0 );
if ( randomChallenge != null )
{
pendingNetFilterEncryption = new NetFilterEncryptionWithHMAC( tempSessionKey );
}
else
{
pendingNetFilterEncryption = new NetFilterEncryption( tempSessionKey );
}
this.Send( encResp );
}