本文整理汇总了C#中Message.getMessageByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# Message.getMessageByteArray方法的具体用法?C# Message.getMessageByteArray怎么用?C# Message.getMessageByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.getMessageByteArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveCallback
private void ReceiveCallback(IAsyncResult AR)
{
Socket current = (Socket)AR.AsyncState;
int received;
try
{
received = current.EndReceive(AR);
}
catch (SocketException x)
{
this.textBox_log.Invoke(new MethodInvoker(delegate ()
{ textBox_log.AppendText("Client forcefully disconnected \n"); }));
current.Close(); // Dont shutdown because the socket may be disposed and its disconnected anyway
_clientSockets.Remove(current);
_disconnectAllClients = true;
return;
}
byte[] recBuf = new byte[received];
Array.Copy(_buffer, recBuf, received);
Int32 role = BitConverter.ToInt32(recBuf,0);
Int32 boxOut = BitConverter.ToInt32(recBuf, 4);
Int32 reqOut = BitConverter.ToInt32(recBuf, 8);
Int32 stock = BitConverter.ToInt32(recBuf, 12);
Int32 u_orders = BitConverter.ToInt32(recBuf, 16);
Int32 roundCode = BitConverter.ToInt32(recBuf, 20);
if (_disconnectAllClients || _clientSockets.Count > 4)
{
Message m = new Message(0, 400, 400, -900); // disconnect all users
byte[] data = m.getMessageByteArray();
current.Send(data);
current.Close(); // Dont shutdown because the socket may be disposed and its disconnected anyway
_clientSockets.Remove(current);
Console.WriteLine("Velikost bufferu pro sokety: " + _clientSockets.Count.ToString());
if(_clientSockets.Count == 0)
{
System.Diagnostics.Process.Start("Server.exe", _PORT.ToString());
Environment.Exit(0);
}
return;
}
if (roundCode == -600) // load configuration + role
{
initClientByRole(current);
//return;
}
else if (reqOut != 0 && boxOut != 0 && roundCode == -500)
{
// chci data - dosly poprve
if (_nextRound[role] == false)
{
lock (_locker)
{
if (isNextRound())
{
Thread.Sleep(2000); // thread collector
}
updeteRoundCounter(role);
updateDataQues(role, boxOut, reqOut);
writeToFile(role, stock, u_orders);
this.textBox_log.Invoke(new MethodInvoker(delegate ()
{ textBox_log.AppendText("Hrac<" + role.ToString() + "> pozaduje: " + reqOut.ToString() + " posila: " + boxOut.ToString() + "\n"); }));
this.tb_LogDetail.Invoke(new MethodInvoker(delegate ()
{ tb_LogDetail.AppendText("flag zpavy " + roundCode.ToString() + " - "); }));
if (isNextRound())
{
this.tb_LogDetail.Invoke(new MethodInvoker(delegate ()
{ tb_LogDetail.AppendText("vsichni odeslaly sva data"); }));
}
else
{
this.tb_LogDetail.Invoke(new MethodInvoker(delegate ()
{ tb_LogDetail.AppendText("pole nextRound obsahuje FALSE - na nekoho se ceka"); }));
}
Message m = new Message(role, 300, 300, -300); // waiting
byte[] data = m.getMessageByteArray();
current.Send(data);
this.tb_LogDetail.Invoke(new MethodInvoker(delegate ()
{ tb_LogDetail.AppendText(" - data odeslana \n"); }));
}
}
else
{
Message m = new Message(role, 300, 300, -300); // waiting
byte[] data = m.getMessageByteArray();
current.Send(data);
}
//return;
}
//.........这里部分代码省略.........
示例2: sendDataByRole
private void sendDataByRole(Int32 role, Socket current)
{
Int32 boxIn;
Int32 boxReqIn;
//resetRoundCounter();
switch (role)
{
case 0:
boxIn = _materialQue[1];
boxReqIn = _infoOrderQue[6];
break;
case 1:
boxIn = _materialQue[3];
boxReqIn = _infoOrderQue[4];
break;
case 2:
boxIn = _materialQue[5];
boxReqIn = _infoOrderQue[2];
break;
case 3:
boxIn = _materialQue[7];
boxReqIn = _infoOrderQue[0];
break;
default:
boxIn = 0;
boxReqIn = 0;
break;
}
if(_roundNumber > 35)
{
if (!_endOfGame)
{
_finalCosts = getFinalCosts();
_averageCosts = Convert.ToInt32(getAverageCosts());
_endOfGame = true;
writeToFinalScore(_finalCosts);
//System.Diagnostics.Process.Start("client.exe", "100 192.168.1.2");
}
Message m = new Message(role, _averageCosts, _finalCosts, -1000); // end game occur
byte[] data = m.getMessageByteArray();
current.Send(data);
}
else
{
Message m = new Message(role, boxIn, boxReqIn, -200); // new round
byte[] data = m.getMessageByteArray();
current.Send(data);
this.tb_LogDetail.Invoke(new MethodInvoker(delegate ()
{ tb_LogDetail.AppendText("data zaslana pro " + role.ToString() + "\n"); }));
}
}
示例3: loadConfigurationRequest
private void loadConfigurationRequest()
{
Message m = new Message(_ROLE, 600, 600, 600, 600, -600);
byte[] buffer = m.getMessageByteArray();
_clientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None);
}
示例4: SendRequest
private void SendRequest()
{
try
{
// pred odeslanim hodnot si upravim sklad a zakazky podle aktualni hodnoty v poli
//int un_order = (int) num_unfulfilled_orders.Value;
int un_order = (int)stringToInt(lbl_dluh.Text);
//int stock = (int) num_stock.Value;
int stock = (int)stringToInt(lbl_sklad.Text);
//int customerRequest = (int)num_in_req_box.Value;
int customerRequest = (int)stringToInt(lbl_reqIn.Text);
updateCLientStockAndUnfulfilledOrders(un_order, stock);
//add2CostSum();
add2Chart(customerRequest);
_roundNumber++;
updateScore();
//Message m = new Message(_ROLE, (Int32)stringToInt(lbl_boxOut.Text), (Int32)num_reqOut.Value, _stock,_unfulfilledOrders ,-500);
Message m = new Message(_ROLE, (Int32)stringToInt(lbl_boxOut.Text), (Int32)stringToInt(lbl_reqOut.Text), _stock, _unfulfilledOrders, -500);
byte[] buffer = m.getMessageByteArray();
// vymazani vsech vstupnich poli (aby doslo ke zmene -> zavola se metoda)
resetAllCells();
//hideControls();
//posladni dat serveru
_clientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None);
this.label2.Invoke(new MethodInvoker(delegate ()
{ label2.Text = "odeslano"; }));
}
catch(Exception e) // nastala chyba -> udelej log
{
this.label1.Invoke(new MethodInvoker(delegate ()
{ label1.Text = "chyba pri odeslani"; }));
if (!_clientSocket.Connected)
{
Console.WriteLine("Vypadlo internetove spojeni");
Environment.Exit(666);
}
}
}
示例5: SendWaitingRequest
private void SendWaitingRequest()
{
Message m = new Message(_ROLE, 300, 300,300,300,-300);
byte[] buffer = m.getMessageByteArray();
_clientSocket.Send(buffer, 0, buffer.Length, SocketFlags.None);
}