c# array

This is a discussion on c# array within the C# Programming forums, part of the General Programming Boards category; I am building a telnet server and I want to no how to make an array. This array needs to ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    23

    c# array

    I am building a telnet server and I want to no how to make an array. This array needs to include a socket, streamreader, streamwriter, and the ipaddress, is this possible?

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Make a class with the information you needed and then add it to a list. Otherwise to make a new array of your class it would be something like:

    Code:
    yourClass[] Something = new yourClass[SIZE]();

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    Might I suggest you learn the basics of the C# language before you try to write a server?

  4. #4
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Rags is correct. You need to have at least a basic understanding of OOP.

    From the criteria you've listed, I would make an object such as:

    Code:
    class UserObject
    {
        public Socket socket;
        public IPAddress ip;
        public StreamReader reader;
        public StreamWriter writer;
    
        public UserObject() { }
    
        public UserObject(Socket socket)
        {
            this.socket = socket;
            this.ip = ((IPEndPoint)socket.RemoteEndPoint).Address;
            this.reader = new StreamReader(new NetworkStream(socket));
            this.writer = new StreamWriter(new NetworkStream(socket));
        }
    }
    Once you've created an object you're happy with, you could either use an ArrayList, or even better would be a List<T> since all the array elements will be the same object type:

    Code:
    List<UserObject> my_users = new List<UserObject>();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 02:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21