Jump to content


Check out our Community Blogs

barkermn01

Member Since 22 May 2009
Offline Last Active Jun 17 2010 08:48 AM
-----

Topics I've Started

Regex and i must be maing a mistake.

01 July 2009 - 10:24 AM

help

private string getQuestType(string name)
{
string type = "";
WebClient client = new WebClient();
sendNotice("Fetching url http://eq2.zam.com/d...html?questname=" + name.Replace(" ", "+"));
String htmlCode = client.DownloadString("http://eq2.zam.com/db/questlist.html?questname=" + name.Replace(" ","+"));
string regex = @"(?<=<table .*>)(?=.*)(?=</table>)";
Regex ex = new Regex(regex, RegexOptions.IgnoreCase);
MatchCollection table = ex.Matches(htmlCode);
regex = "(?<=<tr>)(.*?)(?=</tr>)";
ex = new Regex(regex, RegexOptions.IgnoreCase);
string tbale = table[0].Value;
MatchCollection rows = ex.Matches(tbale);
type = rows[2].Value;
return type;
}


for some reason table dose not = an array so i think my regex is wrong can some one check it please a call that works getQuestType("Orc Defilement");

hi

27 May 2009 - 06:40 AM

Hello,

I'm Martin,

Im a Web Developer for a flooring company in leeds UK,
I have worked in Delphi, VB6, php, c, c++, javascript and learning c# now

i have been working for 13 months commercially, and about 5 years freelance,

I have a large amount of know age and always drive to learn more and advanced ways of programming

Threaded Sockets

22 May 2009 - 04:07 AM

Hi this is my first post i been reading some others so i'm sure there's a brain box that can fix this problem for me

Ok i have a class
class Threads
    {
        int i = 0;
        MySQL mysql = new MySQL();
        TcpListener listener;
        Thread[] threads;
        Thread main;
        NetworkStream[] networkStream;
        Socket[] socketForClient;
        StreamWriter[] streamWriter;
        StreamReader[] streamReader;
        log slog = new log();

        public Threads()
        {
            listener = new TcpListener(8080);
            slog.WriteLine("Thread Server Staring main thread");
            listener.Start();
            main = new Thread(startSocketConection);
        }

        public void startSocketConection()
        {
            listener.BeginAcceptSocket(useSocketConection, listener);
            slog.WriteLine("Main Thread Started");
            startSocketConection();
        }

        public void useSocketConection(IAsyncResult ar)
        {
            slog.WriteLine("Child Thread Started");
            TcpListener listen = (TcpListener)ar.AsyncState;
            socketForClient[i] = listen.EndAcceptSocket(ar);
            threads[i] = new Thread(startSocketConection);
            slog.WriteLine("Started a new Thread");
            networkStream[i] = new NetworkStream(socketForClient[i]);
            streamReader[i] = new StreamReader(networkStream[i]);
            streamWriter[i] = new StreamWriter(networkStream[i]);
            responceHandle(streamReader[i], streamWriter[i]);
        }

        public void responceHandle(StreamReader reader, StreamWriter writer)
        {
            string cmd = reader.ReadLine();
            slog.WriteLine("Message To Server :"+cmd);
            switch (cmd)
            {
                case ("login"):
                {
                    writer.WriteLine("Username");
                    writer.Flush();
                    string user = reader.ReadLine();
                    writer.WriteLine("Password");
                    writer.Flush();
                    string pass = reader.ReadLine();
                    mysql.connect("192.168.0.14", "crm", "root", "r5kjp9lk");
                    string input = "SELECT * FROM `admins` WHERE "+
                            "`user` = '"+user+"' AND `pass` = '"+pass+"'";
                    MySqlDataReader data = mysql.query(input);
                    string cUser = data.GetValue(1).ToString();
                    string cPass = data.GetValue(2).ToString();
                    if (cPass == pass)
                    {
                        writer.WriteLine("Loged In");
                        writer.Flush();
                    }
                    else
                    {
                        writer.WriteLine("Failed");
                        writer.Flush();
                    }
                    break;
                }
            }
            responceHandle(reader, writer);
        }
    }

Now this starts and my main thread starts, I think by the look of the code it is the socket to the application is not connecting to the server.

But this is my code for my client application to connect.

private void button1_Click(object sender, EventArgs e)
        {
            string user = txtUser.Text;
            string pass = txtPass.Text;
            TcpClient server = new TcpClient("192.168.0.14", 8080);
            NetworkStream networkStream = server.GetStream();
            StreamReader streamReader = new StreamReader(networkStream);
            StreamWriter streamWriter = new StreamWriter(networkStream);
            streamWriter.WriteLine("login");
            streamWriter.Flush();
            string data = streamReader.ReadLine();
            if (data == "Username")
            {
                streamWriter.WriteLine(user);
                streamWriter.Flush();
            }
            else
            {
                MessageBox.Show("Error: Connection to server failed");
                Application.Exit();
            }
            data = streamReader.ReadLine();
            if (data == "Password")
            {
                streamWriter.WriteLine(pass);
                streamWriter.Flush();
            }
            else
            {
                MessageBox.Show("Error: Connection to server failed");
                Application.Exit();
            }
            data = streamReader.ReadLine();
            if (data == "Loged In")
            {
                Form2 form2 = new Form2();
                form2.Activate();
                Form form1 = new Form();
                form1.Hide();
            }
            if (data == "Failed")
            {
                lblIncorrect.Visible = true;
            }
        }

any help would be greatly used

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download