Welcome to RenEvo Sign in | Join | Help
in
Home Wiisis Blogs Forums Photos Downloads About

Fun with sockets (c#)

Last post 12-20-2006, 12:30 AM by hinch. 4 replies.
Sort Posts: Previous Next
  •  12-17-2006, 3:43 PM 472

    Fun with sockets (c#)

    right so probably best to start off with the end goal :)   a very basic irc client so i can get my head around c# socket handling and response parsing etc.

     simple bit of code so far but throws up the following error:

     Error    1    The name 'writer' does not exist in the current context


    Below is the code you can ignore some of it as thats due to the UI the bit thats causing the problem is at the bottom

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;
    using System.Threading;


    namespace AngelIRC
    {
        public partial class AngelIRC : Form
        {
            public AngelIRC()
            {
                InitializeComponent();
            }

            private void aboutAngelIRCToolStripMenuItem_Click_1(object sender, EventArgs e)
            {
                // show about box
                AboutBox AboutBox = new AboutBox();
                AboutBox.Show();
            }
            private void exitToolStripMenuItem_Click(object sender, EventArgs e)
            {
                // close application
                Application.Exit();
            }

            private void homepageToolStripMenuItem_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process.Start("http://www.furious-angels.com");
            }

            public static StreamWriter writer;

            private void Form1_Load(object sender, EventArgs e)
            {
                this.ChatWindow.Text = "Welcome to AngelIRC \r\nConnect to an IRC Server using /server servername";
                
                NetworkStream stream;
                TcpClient irc;
                string inputLine;
                StreamReader reader;
                string nickname;
                irc = new TcpClient("www.angel-computers.co.uk", 6667);
                stream = irc.GetStream();
                reader = new StreamReader(stream);
                writer = new StreamWriter(stream);

                while ( (inputLine = reader.ReadLine () ) != null )
                {
                    this.ChatWindow.Text = inputLine;
                }

            }
           
               
        }


    }

  •  12-18-2006, 9:27 AM 479 in reply to 472

    Re: Fun with sockets (c#)

    you forgot to declare the writer Smile

     

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.IO;

    using System.Net;

    using System.Net.Sockets;

    namespace SampleTCP

    {

    class Program

    {

    static void Main(string[] args)

    {

    NetworkStream stream;

    TcpClient irc;

    string inputLine;

    StreamReader reader;

    StreamWriter writer;

    irc = new TcpClient("www.angel-computers.co.uk", 6667);

    stream = irc.GetStream();

    reader = new StreamReader(stream);

    writer = new StreamWriter(stream);

    while ((inputLine = reader.ReadLine()) != null)

    {

    Console.WriteLine(inputLine);

    }

    }

    }

    }


    Advertising has us chasing cars and clothes, working jobs we hate so we can buy shit we don't need.
  •  12-19-2006, 2:36 AM 507 in reply to 479

    Re: Fun with sockets (c#)

    i was trying todo it all inline so to speak instead of splitting off to classes as if i put in

    static void Main(string[] args)

    { }

    around the tcp stream stuff I end up getting compile errors of being unable to declare multiple main's 

     writing stuff out like this always seems so simple until you get into the bloody c# express interface when stuff starts getting scattered all over the place and bits are everywhere.

  •  12-19-2006, 9:13 AM 511 in reply to 507

    Re: Fun with sockets (c#)

    i just did that in a standard console application, you will need to paste the code from the main into your form load.

     


    Advertising has us chasing cars and clothes, working jobs we hate so we can buy shit we don't need.
  •  12-20-2006, 12:30 AM 524 in reply to 511

    Re: Fun with sockets (c#)

    which is exactly what i already have :)

     

    but i see where it was going wrong now i missed out

    StreamWriter writer;

     

     

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems