Exemplo n.º 1
0
		private int GetPort( CommandResponse response )
		{
			int port = 0;
			int pos1 = response.Message.IndexOf("(");
			int pos2 = response.Message.IndexOf(",");
			for( int i =0; i<3; i++ )
			{
				pos1 = pos2 + 1;
				pos2 = response.Message.IndexOf( ",",pos1 );
			}
			pos1 = pos2 + 1;
			pos2 = response.Message.IndexOf( ",",pos1 );
			string PortSubstr1 = response.Message.Substring( pos1, pos2 - pos1 );

			pos1 = pos2 + 1;
			pos2 = response.Message.IndexOf( ")",pos1 );
			string PortSubstr2 = response.Message.Substring( pos1, pos2 - pos1 );

			//evaluate port number
			port = Convert.ToInt32( PortSubstr1 ) * 256;
			port = port + Convert.ToInt32( PortSubstr2 );
			return port;
		}
Exemplo n.º 2
0
		private CommandResponse SendCommand( string method, string parameter )
		{
			// Building the request and writing it to the controolStream
			string request = method;
			if( parameter != null && parameter.Length > 0 )
			{
				request += " "+parameter;
			}
			request += "\r\n";
			byte[] rawBuffer = Encoding.ASCII.GetBytes( request );
			controlStream.Write( rawBuffer, 0, rawBuffer.Length );

			// Reading in our CommandResponse from our controlStream
			CommandResponse retVal = new CommandResponse();
			int bufferSize = 256;
			byte[] buffer = new byte[ bufferSize+1 ];
			while( true )
			{
				// We need to "keep" the buffer and not flush it, therefor using the "secret" read function which preserves the stream and doesn't
				// increase the "stream pointer"
				int bytesRead = controlStream.ReadButDontClear( buffer, 0, bufferSize );
				retVal.message += Encoding.ASCII.GetString( buffer, 0, bytesRead );
				if( bytesRead == 0 )
					break;
			}
			retVal.status = controlStream.StatusCode;
			return retVal;
		}
Exemplo n.º 3
0
		private string GetIP( CommandResponse response )
		{
			StringBuilder ip = new StringBuilder();
			string tmp = null;
			int pos1 = response.Message.IndexOf("(")+1;
			int pos2 = response.Message.IndexOf(",");
			for( int i =0; i < 3; i++ )
			{
				tmp = response.Message.Substring( pos1, pos2 - pos1 ) + ".";
				ip.Append( tmp );
				pos1 = pos2 + 1;
				pos2 = response.Message.IndexOf( ",", pos1 );
			}
			tmp = response.Message.Substring(pos1,pos2-pos1);
			ip.Append( tmp );
			return ip.ToString();
		}