  
		Dennis 
		-Interested User- 
		Posts: 19 
		Joined: Oct 8, 2004 				
		
		 
		 		
	 | 
	
		
			
			Posted: Oct 26, 2004 05:36 PM
			  
			  
			 
			  
			
			  
			Msg. 1 of 5
		  
		This may be of interest to some:
  /////////////////////////////////////////////////////////////////////////////////// // console_stream.cs, version 1.0, copyright 2004 // IQFeed .NET C# sockets example using IQ32.dll // // contributed to the IQFeed Developer Support Forum // by Dennis Sanders (forum username: Dennis) // email: dennissanders@intsvcs.com ///////////////////////////////////////////////////////////////////////////////////
  using System; using System.Threading; using System.Net.Sockets; using System.Runtime.InteropServices;
  public delegate void Callback(int x, int y);
  class IQFeed_NETSocket_Example {     [DllImport("IQ32.dll")]     public static extern void SetCallbackFunction(Callback SetGoodToGo);     [DllImport("IQ32.dll")]     public static extern int RegisterClientApp(IntPtr hClient, string szProductName,          string szProductKey, string szProductVersion);     [DllImport("IQ32.dll")]     public static extern void RemoveClientApp(IntPtr hClient);
      public static bool GoodToGo = false;          public static void SetGoodToGo(int x, int y)     {         GoodToGo = (x==0 && y==0);
          if (x==1 && y==1)          {             Console.WriteLine("IQFeed delivered close message");             RemoveClientApp(IntPtr.Zero);         }     }
      public static void Main()      {         Callback IQFeed_CallBack = new Callback(IQFeed_NETSocket_Example.SetGoodToGo);         SetCallbackFunction(IQFeed_CallBack);
          RegisterClientApp(IntPtr.Zero, "IQFEED_DEMO", "1.0", "1.0");
          while (!GoodToGo)              Thread.Sleep(100);
          try          {             String server = "127.0.0.1";             Int32 port = 5009;             TcpClient client = new TcpClient(server, port);                  NetworkStream stream = client.GetStream();
              String message = "S,KEY\r\n";             Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);             stream.Write(data, 0, data.Length);
              message =  "wMSFT\r\n";             message += "wIBM\r\n";             data = System.Text.Encoding.ASCII.GetBytes(message);             stream.Write(data, 0, data.Length);
              data = new Byte[5120];
              for(int x=0; x<20; x++)              {                    String responseData = String.Empty;                 Int32 bytes = stream.Read(data, 0, data.Length);                 responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);                 Console.Write(responseData);             } 
              client.Close();         } 
          catch (ArgumentNullException e)          {             Console.WriteLine("ArgumentNullException: {0}", e);         } 
          catch (SocketException e)          {             Console.WriteLine("SocketException: {0}", e);         }
          RemoveClientApp(IntPtr.Zero);
          Console.Write("\nPress Enter to continue...");         Console.Read();
          GC.KeepAlive(IQFeed_CallBack);     } }
  ////////////////////////////////////////////////////////////////////////////////////// // end - console_stream.cs //////////////////////////////////////////////////////////////////////////////////////   
  Please post or email any questions, comments or improvements.
  Regards, Dennis Sanders dennissanders@intsvcs.com
  
		
		
 		
		
	 | 
 
	
		  
		Dennis 
		-Interested User- 
		Posts: 19 
		Joined: Oct 8, 2004 				
		
		 
		 		
	 | 
	
		
			
			Posted: Oct 26, 2004 06:56 PM
			  
			  
			 
			  
			
			  
			Msg. 2 of 5
		  
		To build and run console_stream.cs from Visual Studio.NET:
  Create a new Visual C# "Empty Project" in Visual Studio.NET  - In VS.NET go to File->New->Project->Visual C# Projects->Empty Project.  - Type in "console_stream" as the project name and select a location for the project folder.  - Accept the remaining defaults and click OK. Add a new Code File to the Project  - In the Solution explorer (use View if you don't see it), right click "console_stream" (the project name).  - Select Add->Add New Item->Code File.  - Name the Code File console_stream.cs, click Open. Copy and paste the posted code to the editing space for console_stream.cs.  - (...All indents will be magically restored, thank God!...) Add System.dll to the References in your project.  - Right click References (below the project name in the Solution Explorer).  - Select Add Reference, then scroll down the selections under the .NET tab.  - Double-click System.dll, it should appear in Selected Components, then click OK.    (System.dll will be added as System under References. Now Build the Solution   - Change Active Configuration if desired.(the default is Debug, but Release works as well)  - Then select Build->Build Solution
  The project should build with 0 failed, 0 skipped (and no warnings).   - Any build errors can most likely be resolved by adjusting your path or other environment variables.
  You will need a path to IQ32.dll (C:\Program Files\DTN\IQFeed on my computer) in order to successfully run the program.
  To run console_stream.exe from Visual Studio press F5. Or, to run the .exe from Windows; exit Visual Studio and hunt down the console_stream.exe in you newly created project folder. When you find it...double click it.
  If you have any questions or problems, please post or email.
  Regards, Dennis Sanders dennissanders@intsvcs.com 
		
		
 		
		
	 | 
 
	
		  
		Dennis 
		-Interested User- 
		Posts: 19 
		Joined: Oct 8, 2004 				
		
		 
		 		
	 | 
	
		
			
			Posted: Oct 26, 2004 10:23 PM
			  
			  
			 
			  
			
			  
			Msg. 3 of 5
		  
		To build and run console_stream.cs from Windows:
  Create and name a new folder in a location of your choice. Open the new folder in a window on your desktop. Create a new C# Code File in the new folder using the posted code example.  - Open notepad (or a text editor of your choice), copy and paste the posted code to it.  - Using the brackets in the code as a guide, manually replace the indentions that were scrubbed in the forum post.  - Save the contents of notepad to your folder as console_stream.cs Create a new compile.bat file using notepad.  - Select File->New from the notepad menu.  - Type "csc console_stream.cs" (do not include the quote marks).  - Save (File->Save As) the contents of notepad to your folder as build.bat
  You should have two files in your folder; console_stream.cs and build.bat
  Create the executable file console_stream.exe  - Double click build.bat
  A new file, console_stream.exe should appear in the folder (if not, check the possible reasons below). Double click console_stream.exe to run the new example.
  Possible reasons console_stream.exe was not created or will not run. - .NET Framework and/or .NET SDK are not installed on your computer (these are free from Microsoft). - Your path does not include the directory (folder) that contains the .NET build command csc.exe - Your path does not include the IQFeed directory (C:\Program Files\DTN\IQFeed on my computer).
  Executing the build and/or run operations at the Windows Command Prompt will help you diagnose most problems. Feel free to post your ideas/questions/problems to this thread, or send an email.
  Regards, Dennis Sanders dennissanders@intsvcs.com 
		
		
 		
		
	 | 
 
	
		  
		frankzhou 
		-Interested User- 
		Posts: 15 
		Joined: Oct 6, 2004 				
		
		 
		 		
	 | 
	
		
			
			Posted: Oct 27, 2004 03:36 PM
			  
			  
			 
			  
			
			  
			Msg. 4 of 5
		  
		good,do you have a example for history data?  thanks 
		
		
 		
		
	 | 
 
	
		  
		Dennis 
		-Interested User- 
		Posts: 19 
		Joined: Oct 8, 2004 				
		
		 
		 		
	 | 
	
		
			
			Posted: Oct 27, 2004 07:10 PM
			  
			  
			 
			  
			
			  
			Msg. 5 of 5
		  
		frankzhou,
  I am attempting to create a .NET C# version of the VC++ History Example.  However, with my current work load, it may be a bit delayed.  When I have something useful (in whole or in part), I will post it to the developer forum.
  Regards, Dennis 
		
		
 		
		
	 | 
 
	
 
 
 
	|   | 
	
		 
		 
	 | 
 
 
 |