Results 1 to 5 of 5

Thread: Problem with Streams

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Resolved Problem with Streams

    Code:
    		public static void Main() 
    		{
    			Test p = new Test();
    			p.Server = "211.143.183.66";
    			p.Port = 1080;
    			p.Type = 5;
    			p.UserID = "anonymous";
    
    			try
    			{
    				Socket mySocket;
    				if ((mySocket = Connect(p.Server, p.Port)) != null)
    				{
    					NetworkStream myNetworkStream = new NetworkStream(mySocket);
    				
    					if (myNetworkStream.CanWrite == true)
    					{
    						StreamWriter myStreamWriter = new StreamWriter(myNetworkStream);
    						DataBuffer myDataBuffer = new DataBuffer();
    						if (p.Type == 4)
    						{							
    							myDataBuffer.InsertByte(4);
    							myDataBuffer.InsertByte(1);
    							myDataBuffer.InsertInt16(IPAddress.HostToNetworkOrder(p.Port));
    							myDataBuffer.InsertInt32(Convert.ToInt32(IPAddress.Parse(p.Server)));
    							myDataBuffer.InsertCString(p.UserID);
    						}
    						else if (p.Type == 5)
    						{
    							myDataBuffer.InsertByte(5);
    							myDataBuffer.InsertByte(2);
    							myDataBuffer.InsertByte(0);
    							myDataBuffer.InsertByte(2);
    						}
    
    						myDataBuffer.WriteToOutputStream(myStreamWriter);
    
    						if (myNetworkStream.CanRead == true)
    						{
    							StreamReader myStreamReader = new StreamReader(myNetworkStream);
    							DataReader myDataReader = new DataReader(myStreamReader);
    						}
    
    					}
    					else if (myNetworkStream.CanWrite == false)
    					{
    						Console.WriteLine("Network Stream is Not Writeable!");
    					}
    				}
    			}
    
    			catch (Exception e)
    			{
    				Console.WriteLine(e.ToString());
    			}
    
    			Console.ReadLine();
    		}
    I get errors whenever i seem to reference my Stream Reader/Writer to one of my other classes

    These are the errors i get:

    Argument '1': cannot convert from 'System.IO.StreamReader' to 'System.IO.Stream'

    Argument '1': cannot convert from 'System.IO.StreamWriter' to 'System.IO.Stream'

    The best overloaded method match for 'Proxy.GUI.Console.DataBuffer.WriteToOutputStream(System.IO.Stream)' has some invalid arguments

    The best overloaded method match for 'Proxy.GUI.Console.DataReader.DataReader(System.IO.Stream)' has some invalid arguments


    Thank You For The Help

    - Joel
    Last edited by BaDDBLooD; Feb 1st, 2006 at 06:26 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Streams

    That' because the StreamReader and StreamWriter classes are not derived from the Stream class. They read from and write to streams but they are not streams themselves. They each have a BaseStream property that is a Stream object.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Streams

    You got in before I edited my previous post. Take another look.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Problem with Streams

    Quote Originally Posted by jmcilhinney
    That' because the StreamReader and StreamWriter classes are not derived from the Stream class. They read from and write to streams but they are not streams themselves. They each have a BaseStream property that is a Stream object.
    You are like a programming god, thank you so much!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem with Streams

    Quote Originally Posted by BaDDBLooD
    You are like a programming god, thank you so much!
    More like a programming buffoon in really nice clothes.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width