Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Null Reference Exception?

Name: cocksucks 2010-12-23 13:30

Sup /prog/

Im trying to create a multi-client server in C#. I'm making it access an ArrayList of the same class. (I just started C# a week ago and are trying to gain experience)

Anyways, once it gets to the clientThread (I pass the index of the ArrayList in which is contained TcpClient). I get a nullreference exception.

Why?

Name: Anonymous 2010-12-23 13:31

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

namespace AS
{
    public partial class frmMain : Form
    {
        private encMod enc = new encMod();
        private TcpListener tcpListen = new TcpListener(IPAddress.Any, 9040);
        private Thread threadListen;
        private ArrayList clients = new ArrayList();

        public frmMain()
        {
            InitializeComponent();
            threadListen = new Thread(new ThreadStart(threadListenFunction));
            threadListen.Start();

        }

        private void threadListenFunction()
        {
            this.tcpListen.Start();

            while (true)
            {
                int client = clients.Count;
                this.clients.Insert(client, new clientMod());
                ((clientMod)this.clients[client]).clientID = client;
                ((clientMod)this.clients[client]).tcpClient = this.tcpListen.AcceptTcpClient();

                Thread clientThread = new Thread(new ParameterizedThreadStart (threadClient));

                clientThread.Start(client);
            }
        }

        private void threadClient(object ctcpClient)
        {
            int client = (int)ctcpClient;

            NetworkStream clientStream = ((clientMod)this.clients[client]).tcpClient.GetStream();

            byte[] buffer = new byte[1024];
            long read = 0;

            try
            {
                if (clientStream.CanRead)
                {

                    while ((read = clientStream.Read(buffer, 0, 1024)) != 0)
                    {
                        this.txtRecieved.AppendText(enc.EncryptString(UnicodeEncoding.Unicode.GetString(buffer), ((clientMod)this.clients[client]).encKey));
                    }
                }

            }
            catch
            {
            }

            this.clients.RemoveAt(client);
        }

        private void txtSend_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtRecieved.AppendText(enc.EncryptString(txtSend.Text, 127));
                txtSend.Clear();

                e.Handled = true;
            }
        }

        private void lstConnections_Click(object sender, EventArgs e)
        {
            txtSend.Focus();
        }

        private void txtRecieved_KeyPress(object sender, KeyPressEventArgs e)
        {
            txtSend.Focus();
            txtSend.SelectedText = e.KeyChar.ToString();

            e.Handled = true;
        }

        private void lstConnections_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtSend.Focus();
                e.Handled = true;
            }
        }

        private void lblArrow_Click(object sender, EventArgs e)
        {
            txtSend.Focus();
        }
    }
}

Name: Anonymous 2010-12-23 13:48

OP here.

I'm a faggot who can't sage or use [code] tags, don't help me.

Name: cocksucks 2010-12-23 13:58

OP here, first time posting. umad?

Name: Anonymous 2010-12-23 14:02

>>4
back to /b/ plz

Name: Anonymous 2010-12-23 14:05

OP here.

I like the imageboards. I hope you like my shitty imageboard habits.

Name: Anonymous 2010-12-23 14:18

>>5
fuck off faggot

Name: Anonymous 2010-12-23 14:19

OP use code tags but don't sage your own thread. >>3,5 are fucking fags.

Name: sage 2010-12-23 14:19

>>6
Oh but I do, and I'll be sure to use [code] tags. Next time, as for being able to use sage...

Name: OP 2010-12-23 14:20

LOL how embarrasing

Name: Anonymous 2010-12-23 14:33

lol umad tits or gtfo pls moar halp anon is legion lolololololo
GET BACK TO /b/, ``FAGGOT''

Name: Anonymous 2010-12-23 15:01

>>11
NO U

Name: Anonymous 2010-12-23 15:15

This thread has been closed and replaced with the following thread:

Subject:
C# K&K equivalent
Name:
Email:


I'm looking for a book that covers the C# standard library, just like K&K does with C.

Name: Anonymous 2010-12-23 15:46

fuque I mena K&R

Name: Anonymous 2010-12-23 15:59

KKK & R

Name: VIPPER 2010-12-23 16:12

>>15
JEWS NIGGERS

Name: Anonymous 2010-12-23 16:29

>>16
Rude!

Name: Anonymous 2010-12-23 16:39

>>13
The "book" you are in a search for is called "MSDN", freely available over the Internet or for a local installation.

If your previous experience was limited to men, or maybe even the stuff like Python documentation, you might find this idea strange at first.

Name: Anonymous 2010-12-23 16:43

>>18
I've had experience with MSDN before and I can assure you that it is a very helpful resource when you have to write some shitty academic fib calculator, but is completely useless in real world.

Name: Anonymous 2010-12-23 17:00

>>19
Do you like my bitch teats?

Name: VIPPER 2010-12-23 17:11

You will all be kill by JEWS.
Except >>16

Name: Anonymous 2011-01-31 19:47

<-- check em dubz

Name: Anonymous 2011-02-02 22:33


Don't change these.
Name: Email:
Entire Thread Thread List