public static void ConnectToServer(ConnectionInfo ConnectionInfo, ConnectionMode ConnectionMode, String[] Params)
 {
     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.StreamPort);
     try {
         serverConnection.Connect(connectionEndpoint);
     } catch (SocketException Se) {
         if (Se.ErrorCode == 10061) {
             Log.AddStatusText("Stream server @ " + ConnectionInfo.IPAddress + ":" + ConnectionInfo.StreamPort + " refused connection.");
             MessageBox.Show("The Stream Server refused connection. Is the server running? Are ports forwarded?");
         }
     }
     if (serverConnection.Connected) {
         String tempCreate = Protocol.CreateSTREAMSONG(Params[0]);
         Console.WriteLine("To ServerStream:\t" + tempCreate);
         serverConnection.Send(Encoding.UTF8.GetBytes(tempCreate + "\x4"));
         WaitForData(serverConnection);
     } else {
         Forms.MainFrm.UpdateStatusLabel("Ready");
     }
 }
 /// <summary>
 /// RemotePlaylist constructor. Sets various internal variables.
 /// </summary>
 /// <param name="iServerGUID">GUID of server hosting the playlist</param>
 /// <param name="iPlaylistName">Name of the playlist</param>
 /// <param name="iSongCount">Number of songs in the playlist</param>
 /// <param name="PlaylistGUID">GUID of the playlist</param>
 public RemotePlaylist(String iServerGUID, String iName, int iSongCount, String PlaylistGUID)
 {
     Name = iName;
     SongCount = iSongCount;
     ConnectionInfo = Functions.ServerGUIDToConnectionInfo(Config.Instance.ConnectionInfoList, iServerGUID);
     GUID = PlaylistGUID;
 }
 private void OKCmd_Click(object sender, EventArgs e)
 {
     IPHostnameTxt.Text = IPHostnameTxt.Text.Trim();
     PortTxt.Text = PortTxt.Text.Trim();
     PasswordTxt.Text = PasswordTxt.Text.Trim();
     DescriptionTxt.Text = DescriptionTxt.Text.Trim();
     ConnectionInfo tempConnInfo = new ConnectionInfo();
     if (Mode == "Edit") {
         tempConnInfo = OrgConnInfo;
     }
     UriHostNameType hostnameType = Uri.CheckHostName(IPHostnameTxt.Text);
     if (hostnameType == UriHostNameType.IPv4) {
         tempConnInfo.IPAddress = IPHostnameTxt.Text; tempConnInfo.Hostname = "";
     } else if (hostnameType == UriHostNameType.Dns) {
         tempConnInfo.IPAddress = ""; tempConnInfo.Hostname = IPHostnameTxt.Text;
     } else {
         MessageBox.Show("IP Address or Hostname appears to be invalid. Please choose a valid hostname to continue."); return;
     }
     if (Mode == "Edit") {
         Config.Instance.ConnectionInfoList.Remove(OrgConnInfo);
     }
     tempConnInfo.IPAddress = IPHostnameTxt.Text;
     tempConnInfo.InfoPort = Convert.ToInt32(PortTxt.Text);
     tempConnInfo.Description = DescriptionTxt.Text;
     tempConnInfo.RequiresPassword = ServerPasswordChk.Checked;
     tempConnInfo.Password = PasswordTxt.Text;
     if (tempConnInfo.InternalGUID == null) {
         tempConnInfo.InternalGUID = Guid.NewGuid().ToString();
     }
     Config.Instance.ConnectionInfoList.Add(tempConnInfo);
     Config.Instance.Save();
     Forms.MainFrm.PushSettingsToForm();
     this.Close();
 }
 /// <summary>
 /// Public constructor for createing a Server object
 /// </summary>
 /// <param name="iSocket">Socket associated with Server object</param>
 /// <param name="iServerInfoIndex">Index number of the associated Server object</param>
 public ServerInfo(Socket iSocket, int iServerInfoIndex, ConnectionInfo iConnectionInfo, ConnectionMode iConnectionMode)
 {
     Socket = iSocket;
     Index = iServerInfoIndex;
     ConnectionInfo = iConnectionInfo;
     ConnectionMode = iConnectionMode;
     ConnectionStatus = ConnectionStatus.Pending;
     OnServerConnect();
 }
 /// <summary>
 /// Sets the operating mode for the Connection Form. Edit mode.
 /// </summary>
 /// <param name="iMode">String containing the Operating Mode</param>
 /// <param name="ConnectionInfo">ConnectionInfo object containing the ConnectionInfo to be populated.</param>
 public void SetMode(String iMode, ConnectionInfo ConnectionInfo)
 {
     SetMode(iMode);
     OrgConnInfo = ConnectionInfo;
     IPHostnameTxt.Text = ConnectionInfo.IPAddress;
     PortTxt.Text = ConnectionInfo.InfoPort.ToString();
     DescriptionTxt.Text = ConnectionInfo.Description;
     PasswordTxt.Text = ConnectionInfo.Password;
     ServerPasswordChk.Checked = ConnectionInfo.RequiresPassword;
 }
示例#6
0
 /// <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");
     }
 }