本文整理汇总了C#中System.Net.Connection.SendObject方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.SendObject方法的具体用法?C# Connection.SendObject怎么用?C# Connection.SendObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Connection
的用法示例。
在下文中一共展示了Connection.SendObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToConnectionList
// Receive incoming initial Connection messages from Clients...
public static void AddToConnectionList(PacketHeader header, Connection connection, string Connection)
{
// Add incoming IP Address to HashSet list...
ConnectionsList.Add(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + "|" + Connection);
// Respond to sender that they are succesfully connected.
connection.SendObject("Connected", "CONNECTED!");
Console.WriteLine("\n" + connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " has CONNECTED!");
// Send all active connections to all active connections for Client List.
foreach (var item in NetworkComms.GetExistingConnection())
{
foreach (var items in ConnectionsList.Distinct())
{
item.SendObject("Connection", items);
}
}
/* Old method to create files on hard disk for testing the code...
if (!File.Exists(ConnectionFilePath))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(ConnectionFilePath))
{
}
}
using (StreamWriter sw = File.AppendText(ConnectionFilePath))
{
sw.WriteLine(connection.ConnectionInfo.RemoteEndPoint.Address.ToString());
} */
}
示例2: AddToConnectionList_Server
private static void AddToConnectionList_Server(PacketHeader header, Connection connection, string Connection)
{
// Add incoming IP Address to HashSet list...
ConnectionsList_Server.Add(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + "|" + Connection);
// Respond to sender that they are succesfully connected.
connection.SendObject("Connected", "CONNECTED!");
//richTextBox1.AppendText("\n" + connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " has CONNECTED!" + Environment.NewLine);
// Send all active connections to all active connections for Client List.
foreach (var item in NetworkComms.GetExistingConnection())
{
foreach (var items in ConnectionsList_Server.Distinct())
{
item.SendObject("Connection", items);
}
}
}
示例3: HandleIncomingMessage
private static void HandleIncomingMessage(PacketHeader header, Connection connection, iRTVOMessage incomingMessage)
{
logger.Log(NLog.LogLevel.Debug,"HandleIncomingMessage: {0}", incomingMessage.ToString());
if (isServer && (incomingMessage.Command == "AUTHENTICATE"))
{
if ((incomingMessage.Arguments == null) || (incomingMessage.Arguments.Count() != 1))
{
logger.Error("HandleIncomingMessage: Wrong arguments to Authenticate from {0}", connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(false,-100);
return;
}
if (String.Compare(_Password, Convert.ToString(incomingMessage.Arguments[0])) != 0)
{
logger.Error("HandleIncomingMessage: Worng Password from {0}", connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(false,-200);
}
logger.Info("Client {0} authenticated.", connection.ConnectionInfo.NetworkIdentifier);
isAuthenticated[connection.ConnectionInfo.NetworkIdentifier] = true;
connection.SendObject("iRTVOMessage", new iRTVOMessage(NetworkComms.NetworkIdentifier, "AUTHENTICATED"));
if (_NewClient != null)
_NewClient(connection.ConnectionInfo.NetworkIdentifier);
return;
}
if (!isServer && (incomingMessage.Command == "AUTHENTICATED"))
{
if (_ClientConnectionEstablished != null)
_ClientConnectionEstablished();
return;
}
if (isServer && (!isAuthenticated.ContainsKey(connection.ConnectionInfo.NetworkIdentifier) || !isAuthenticated[connection.ConnectionInfo.NetworkIdentifier]))
{
logger.Warn("HandleIncomingMessage: Command from unauthorized client {0}",connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(false,-300);
return;
}
iRTVORemoteEvent e = new iRTVORemoteEvent(incomingMessage);
if (_ProcessMessage != null)
{
using ( TimeCall tc = new TimeCall("ProcessMessage") )
_ProcessMessage(e);
}
// Handler signals to abort this connection!
if (e.Cancel)
{
logger.Error("HandleIncomingMessage: ProcessMessage signaled to close client {0}", connection.ConnectionInfo.NetworkIdentifier);
connection.CloseConnection(true, -400);
}
else
{
if (isServer && e.Forward)
ForwardMessage(incomingMessage);
}
}
示例4: HandleNewConnection
private static void HandleNewConnection(Connection connection)
{
if (isServer) // if we are the server, start the handshake
{
logger.Info("Connection from {0} ({1}).", connection.ConnectionInfo.NetworkIdentifier,connection.ConnectionInfo);
connection.SendObject("iRTVOAuthenticate"); // Signal client that it must authenticate to us;
}
else
{
logger.Info("Connection to Server established");
serverConnection = connection;
}
}
示例5: HandleAuthenticateRequest
private static void HandleAuthenticateRequest(PacketHeader header, Connection connection, object incomingMessage)
{
logger.Info("Authentication Request Received from {0} ({1})", connection.ConnectionInfo.NetworkIdentifier, connection);
connection.SendObject("iRTVOMessage", new iRTVOMessage(NetworkComms.NetworkIdentifier,"AUTHENTICATE",_Password));
}
示例6: VersionCheck
// Check Client version and send update signal if needed.
public static void VersionCheck(PacketHeader header, Connection connection, string version)
{
if (version == LatestClientVersion)
{
Console.WriteLine(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is up to date.");
// Display all connected Clients...
Console.WriteLine("\nCurrent Clients:");
foreach (var item in ConnectionsList) { Console.WriteLine(item); }
}
else
{
connection.SendObject("version", LatestClientVersion);
Console.WriteLine(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is version " + version + ", and has been notified of available update.");
// Display all connected Clients...
Console.WriteLine("\nCurrent Clients:");
foreach (var item in ConnectionsList) { Console.WriteLine(item); }
}
}
示例7: VersionCheck_Server
// Check Client version and send update signal if needed.
private static void VersionCheck_Server(PacketHeader header, Connection connection, string version)
{
if (version == LatestClientVersion)
{
richTextBox1.AppendText(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is up to date." + Environment.NewLine);
// Display all connected Clients...
richTextBox1.AppendText("\nCurrent Clients:" + Environment.NewLine);
foreach (var item in ConnectionsList_Server) { richTextBox1.AppendText(item + Environment.NewLine); }
}
else
{
connection.SendObject("version", LatestClientVersion);
richTextBox1.AppendText(connection.ConnectionInfo.RemoteEndPoint.Address.ToString() + " is version " + version + ", and has been notified of available update." + Environment.NewLine);
// Display all connected Clients...
richTextBox1.AppendText("\nCurrent Clients:" + Environment.NewLine);
foreach (var item in ConnectionsList_Server) { richTextBox1.AppendText(item + Environment.NewLine); }
}
}