Results 1 to 11 of 11

Thread: Reading and Parsing Text From a Text Document

Threaded View

  1. #1

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

    Reading and Parsing Text From a Text Document

    Code:
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;
    
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Proxy
    {
    	private const string FILE_NAME = "MyFile.txt";
    
    	/// <summary>
    	/// The main entry point for the application.
    	/// </summary>
    
    	public static void Main(String[] args) 
    	{
    		if (!File.Exists(FILE_NAME)) 
    		{
    			Console.WriteLine("{0} does not exist.", FILE_NAME);
    			return;
    		}
    		else
    		{
    			StreamReader sr = File.OpenText(FILE_NAME);
    			string input;
    			while ((input = sr.ReadLine()) != null) 
    			{
    				try
    				{
    					Socket s = ConnectSocket(server, port);
    				}
    
    				catch (Exception e)
    				{
    					Console.WriteLine(e.ToString());
    				}
    			}
    
    			Console.WriteLine ("End Of {0}", FILE_NAME);
    			sr.Close();
    		}
    
    		Console.ReadLine();
    	}
    
    	private static Socket ConnectSocket(string server, int port)
    	{
    		Socket s = null;
    		IPHostEntry hostEntry = null;
            
    		hostEntry = Dns.Resolve(server);
    
    		foreach(IPAddress address in hostEntry.AddressList)
    		{
    			IPEndPoint ipe = new IPEndPoint(address, port);
    			Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
    
    			Console.WriteLine("Establishing Connection To {0} on Port {1} ...", address, port);
    			tempSocket.Connect(ipe);
    
    			if(tempSocket.Connected == true)
    			{
    				Console.WriteLine("Connection Established!");
    				s = tempSocket;
    				break;
    			}
    			else
    			{
    				Console.WriteLine("Connection Failed!");
    				continue;
    			}
    		}
    
    		return s;
    	}
    }
    I have my Addresses in the Text Document formatted a specific way.

    Example: 255.255.255.255:1080@SOCKS4

    I'm trying to get all three different pieces of information and store them. I also want to make sure all pieces of information have been entered, as well as check for any formatting errors, maybe tell the user what line it was on etc..

    However, i really have no idea how to do this... i was experimenting with some input.split but that just did not work out how i was hoping...

    Thanks

    - Joel
    Last edited by BaDDBLooD; Jan 29th, 2006 at 02:24 PM.

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