本文整理汇总了C#中Packet.FromString方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.FromString方法的具体用法?C# Packet.FromString怎么用?C# Packet.FromString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.FromString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadServer
private void ReadServer()
{
//if (Setup())
{
byte[] bb;
string sMsg;
while (!bStopThreads)
{
try
{
bb = new byte[500];
//stm.ReadTimeout = 1000;
int k = stm.Read(bb, 0, 500);
sMsg = "";
for (int i = 0; i < k; i++)
sMsg += Convert.ToChar(bb[i]);
Debug.WriteLine("Client Heard: " + sMsg);
Packet p = new Packet();
p.FromString(sMsg);
InputQueue.Enqueue(p);
}
catch (Exception e)
{
//MessageBox.Show(e.ToString());
//stm.ReadTimeout = 1000;
}
Thread.Sleep(100);
}
}
}
示例2: ServerListen
private void ServerListen()
{
if (ServerSetup())
{
byte[] b;
while (!bStopThread)
{
try
{
b = new byte[500];
socket.ReceiveTimeout = 1000;
int k = socket.Receive(b);
lock (text)
{
text = "";
for (int i = 0; i < k; i++)
text += Convert.ToChar(b[i]);
if (text != "")
{
Debug.WriteLine("Lobby Listener Heard: " + text);
Packet p = new Packet();
p.FromString(text);
InputQueue.Enqueue(p);
}
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
//MessageBox.Show(e.Message);
//s.ReceiveTimeout = 1001;
}
}
/* clean up */
if(socket!=null)
socket.Close();
myList.Stop();
}
}
示例3: ProcessServerPackets
private void ProcessServerPackets(object sender, ElapsedEventArgs e)
{
if (InputQueue.Count > 0)
{
//string data = InputQueue.Dequeue().sMsg;
//string[] word = data.Split("|".ToCharArray());
Packet p = new Packet();
if (InputQueue.Peek().type == Packet.pType.TO_CLIENT)
{
p.FromString(InputQueue.Dequeue().ToString());
switch (p.info)
{
#region CONNECTION INFO
case Packet.pInfo.CONNECTION_INFO:
this.iPort = Convert.ToInt32(p.GetFieldValue("PORT"));
this.sKey = p.GetFieldValue("CLIENT KEY");
stm.Close();
tcpclnt.Close();
stm.Dispose();
ConnectToServer(false, sAlias);
p.type = Packet.pType.TO_CLIENT_GUI;
OutputQueue.Enqueue(p);
Packet p1 = new Packet(Packet.pType.TO_SERVER,
Packet.pInfo.CLIENT_LIST_ADD,
Packet.pDelivery.TARGETED,
this.sKey,
"");
p1.AddFieldValue("ALIAS",sAlias);
OutputQueue.Enqueue(p1);
bConnected = true;
break;
#endregion
case Packet.pInfo.CLIENT_LIST_REFRESH:
break;
/*
#region NEW GAME
case Packet.pInfo.NEW_GAME:
SendPacket(new Packet(Packet.pType.TO_CLIENT_GUI,
Packet.pInfo.NEW_GAME,
Packet.pDelivery.TARGETED,
"",
"",
p.sMessage);
break;
#endregion */
}
}
}
}
示例4: ReadClient
private void ReadClient()
{
byte[] b;
string sMsg = "";
while (!bStopThreads)
{
try
{
b = new byte[500];
//socket.ReceiveTimeout = 200;
int k = socket.Receive(b);
sMsg = "";
for (int i = 0; i < k; i++)
sMsg += Convert.ToChar(b[i]);
sMsg.Replace("\n", "");
Packet p = new Packet();
p.FromString(sMsg);
InputQueue.Enqueue(p);
Debug.WriteLine("Server Heard: '" + sMsg + "'");
}
catch (Exception e)
{
}
Thread.Sleep(100);
}
socket.Close();
myListener.Stop();
}
示例5: SendingTestRoutine
private IEnumerator SendingTestRoutine()
{
Packet packet = new Packet();
packet.FromString("{\"id\":2533,\"nr\":\"00000\",\"data\":\"BVH7QJU1H2C0GDX12EI4MS0KBSHN7GSJ6656L0RFB1YS5IF9N5E5AO93VYK5HZ7N2J\"}");
int packetCounter = 0;
while (!stopSendingRoutine)
{
packet.nr = packetCounter.ToString();
++packetCounter;
SendData(packet.ToString());
yield return new WaitForEndOfFrame();
}
stopSendingRoutine = false;
}
示例6: ExtractMessagesFromRawBuffer
private void ExtractMessagesFromRawBuffer(string receivedMsg)
{
// Append the received data to the raw buffer
receivedMsgBuffer.Append(receivedMsg);
string completeMessages = receivedMsgBuffer.ToString();
int index = 0;
if ((index = completeMessages.LastIndexOf('}')) != -1)
{
receivedMsgBuffer.Remove(0, index + 1);
while (messageBufferLock) { }
messageBufferLock = true;
// Extract the complete messages and put them in a buffer
completeMessages = completeMessages.Substring(0, index + 1);
int begin = 0;
int end = 0;
while ((end = completeMessages.IndexOf('}', begin)) != -1)
{
string message = completeMessages.Substring(begin, end - begin + 1);
begin = end + 1;
completeMsgBuffer.Add(message);
Packet packet = new Packet();
packet.FromString(message);
if (measureTime && timestamps.ContainsKey(packet.id + packet.nr))
{
Timestamp timestamp = timestamps[packet.id + packet.nr];
timestamp.second = Stopwatch.GetTimestamp();
}
}
messageBufferLock = false;
}
}
示例7: Update
protected void Update()
{
if (completeMsgBuffer.Count > 0)
{
// Extract complete messages from the buffer
string messages = string.Empty;
while (messageBufferLock) { }
messageBufferLock = true;
List<string> messagesCopy = new List<string>(completeMsgBuffer);
completeMsgBuffer.Clear();
messageBufferLock = false;
// Send the individual messages to the browser
foreach (string completeMessage in messagesCopy)
{
Packet packet = new Packet();
packet.FromString(completeMessage);
if (measureTime && timestamps.ContainsKey(packet.id + packet.nr))
{
Timestamp timestamp = timestamps[packet.id + packet.nr];
timestamp.third = Stopwatch.GetTimestamp();
}
#if !UNITY_EDITOR
Application.ExternalCall(onMessageCallback, completeMessage);
#else
UnityEngine.Debug.Log(completeMessage);
#endif
}
}
}
示例8: SendData
public void SendData(string msg)
{
byte[] data = Encoding.UTF8.GetBytes(msg);
if (measureTime)
{
Packet packet = new Packet();
packet.FromString(msg);
Timestamp timestamp = new Timestamp();
timestamp.nr = packet.nr;
timestamp.first = Stopwatch.GetTimestamp();
timestamps.Add(packet.id + packet.nr, timestamp);
}
switch (channel)
{
case Channel.RELIABLE:
NetworkStream stream = TCPClient.GetStream();
try
{
stream.BeginWrite(data, 0, data.Length, new AsyncCallback(EndTCPSend), stream);
}
catch (Exception err)
{
#if !UNITY_EDITOR
Application.ExternalCall(onErrorCallback, "Received error on TCP channel: " + err.ToString());
#else
UnityEngine.Debug.LogError("Received error on TCP channel: " + err.ToString());
#endif
}
break;
case Channel.UNRELIABLE:
try
{
sendingUDPClient.BeginSend(data, data.Length, new AsyncCallback(EndUDPSend), sendingUDPClient);
}
catch (Exception err)
{
#if !UNITY_EDITOR
Application.ExternalCall(onErrorCallback, "Received error on UDP channel: " + err.ToString());
#else
UnityEngine.Debug.LogError("Received error on UDP channel: " + err.ToString());
#endif
}
break;
}
}