当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionMode.ToString方法代码示例

本文整理汇总了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");
     }
 }
开发者ID:SpectralCoding,项目名称:boobox-client,代码行数:46,代码来源:CommInfo.cs


注:本文中的ConnectionMode.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。