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?
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 ...
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?
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]();
Might I suggest you learn the basics of the C# language before you try to write a server?
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:
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: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)); } }
Code:List<UserObject> my_users = new List<UserObject>();