C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-14-2009, 09:16 PM   #1
Registered User
 
Join Date: Mar 2009
Posts: 21
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?
Mastermosley is offline   Reply With Quote
Old 03-15-2009, 12:31 AM   #2
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 468
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]();
valaris is offline   Reply With Quote
Old 03-15-2009, 06:39 AM   #3
and the Hat of Ass
 
Join Date: Dec 2007
Posts: 813
Might I suggest you learn the basics of the C# language before you try to write a server?
rags_to_riches is offline   Reply With Quote
Old 03-15-2009, 09:00 AM   #4
Registered User
 
Join Date: Mar 2009
Location: england
Posts: 95
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>();
theoobe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
allocation and reallocation of memory dynamically of an integer array zamir C++ Programming 16 05-29-2009 07:25 PM
Array coping into another array?or function returning array baniakjr C++ Programming 6 11-09-2006 03:28 AM
[question]Analyzing data in a two-dimensional array burbose C Programming 2 06-13-2005 07:31 AM
Unknown Memory Leak in Init() Function CodeHacker Windows Programming 3 07-09-2004 09:54 AM
Quick question about SIGSEGV Cikotic C Programming 30 07-01-2004 07:48 PM


All times are GMT -6. The time now is 02:13 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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