本文整理汇总了C#中ConnectionMode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMode.ToString方法的具体用法?C# ConnectionMode.ToString怎么用?C# ConnectionMode.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionMode
的用法示例。
在下文中一共展示了ConnectionMode.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectToServer
/// <summary>
/// Connect to a server.
/// </summary>
/// <param name="ConnectionInfo">ConnectionInfo object containing connection information</param>
/// <param name="ConnectionMode">Mode describing the type of connection</param>
/// <param name="Params">Optional params to be passed to the ServerInfo object</param>
public static void ConnectToServer(ConnectionInfo ConnectionInfo, ConnectionMode ConnectionMode, String[] Params)
{
if ((ConnectionMode != ConnectionMode.FirstConnect) && (ConnectionMode != ConnectionMode.SongRequest)) {
Forms.MainFrm.UpdateStatusLabel("Connecting to \"" + ConnectionInfo.Description + "\" (" + ConnectionMode.ToString() + " mode).");
}
Log.AddStatusText("Connecting to server (" + ConnectionMode.ToString() + " mode): " + ConnectionInfo.Description);
if (ConnectionInfo.Hostname != "") {
Log.AddStatusText("Attempting to resolve hostname: " + ConnectionInfo.Hostname);
IPHostEntry hostInfo = Dns.GetHostEntry(ConnectionInfo.Hostname);
if (hostInfo.AddressList.Length > 0) {
ConnectionInfo.IPAddress = hostInfo.AddressList[0].ToString();
Log.AddStatusText("Hostname (" + ConnectionInfo.Hostname + ") resolved to " + ConnectionInfo.IPAddress + ".");
}
}
serverConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint connectionEndpoint = new IPEndPoint(IPAddress.Parse(ConnectionInfo.IPAddress), ConnectionInfo.InfoPort);
try {
serverConnection.Connect(connectionEndpoint);
} catch (SocketException Se) {
if (Se.ErrorCode == 10061) {
ServerManager.SetOffline(ConnectionInfo.InternalGUID);
Log.AddStatusText("Info server @ " + ConnectionInfo.IPAddress + ":" + ConnectionInfo.InfoPort + " refused connection.");
if ((ConnectionMode != ConnectionMode.FirstConnect) && (ConnectionMode != ConnectionMode.OnlineTest) && (ConnectionMode != ConnectionMode.SongRequest)) {
MessageBox.Show("The Info Server refused connection. Is the server running? Are ports forwarded?");
}
if (ConnectionMode == ConnectionMode.OnlineTest) {
Forms.MainFrm.UpdateStatusLabel("Server \"" + ConnectionInfo.Description + "\" is offline. Song skipped.");
}
}
}
if (serverConnection.Connected) {
ServerInfo tempServerInfo = new ServerInfo(serverConnection, SocketCounter, ConnectionInfo, ConnectionMode);
if (Params.Length > 0) { tempServerInfo.ConnectionParams = Params; }
ServerInfoList.Add(tempServerInfo);
WaitForData(tempServerInfo);
Interlocked.Increment(ref SocketCounter);
} else {
Forms.MainFrm.UpdateStatusLabel("Ready");
}
}