All pastes #43868 Raw Edit

Mine

public text v1 · immutable
#43868 ·published 2006-03-01 01:10 UTC
rendered paste body
    public partial class ServerPanel : Form
    {
        private int portNum = 1337;
        private IPAddress ipAd = IPAddress.Any;
        private Thread listenThread;
        private TcpListener myList;

        private void startListen()
        {
            Socket s = myList.AcceptSocket();
            listenStatusLog("Connection accepted from " + s.RemoteEndPoint);

            byte[] b = new byte[100];
            int k = s.Receive(b);
            listenStatusLog("Recieved...");
            for (int i = 0; i < k; i++)
                listenStatusLog(Convert.ToString(b[i]));

            ASCIIEncoding asen = new ASCIIEncoding();
            s.Send(asen.GetBytes("The string was recieved by the server."));
            listenStatusLog("\nSent Acknowledgement");
            /* clean up */
            s.Close();
            myList.Stop();
        }
        private void listenButtonStart_Click(object sender, EventArgs e)
        {
            try
            {
                /* Initializes the Listener */
                myList = new TcpListener(ipAd, portNum);

                /* Start Listeneting at the specified port */
                myList.Start();

                listenStatusLog("The server is running at port "+portNum+" @ "+ipAd.ToString()+"...");
                listenStatusLog("The local End point is:" + myList.LocalEndpoint);
                listenStatusLog("Waiting for a connection.....");

                // put listener on a new thread and start
                listenThread = new Thread(new ThreadStart(this.startListen()));
// ----------------------------------
// the above line gives me the following error:
// Method name expected
// its referring to the "this.startListen()" part...
// ----------------------------------
                listenThread.IsBackground = true;
                listenThread.Start();
            }
            catch (Exception err)
            {
                listenStatusLog("Error..... " + err.StackTrace.ToString());
            }    
        }

        public ServerPanel()
        {
            InitializeComponent();
            listenPortBox.Text = portNum.ToString();
            listenHostBox.Items.Clear();
        }
    }