• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 659
  • Last Modified:

Whats wrong with code?

Hi experts,

I am new in C#. I dont know much about it. I am trying to run a sample code of chat server in C#.
First I created a windows application in C# through visual studion .net frame work wizard.
Then I added a new form and copy the code from sample file into it. When I complied it, it gives me errors. The error lines and its description is below. Any body can help me to run this code? I will be thankfult to hime



******** Code Start
using System;
using System.IO;
using System.Collections;
using System.Runtime.Remoting;
using System.WinForms ;   //------------------------------------- error on this line
using System.Runtime.Remoting.Channels.HTTP;   //---------- error on this line

namespace com.icommware.PublishSubscribe
{
 
      public class Topic : MarshalByRefObject
      {
 
 
            ArrayList userlist = new ArrayList() ;
            ArrayList textboxlist = new ArrayList() ;
            ArrayList listboxlist = new ArrayList() ;
            ///<summary>
            ///      Input : string username (by value) and RichTextBox , ListBox (by refrence)
            ///   Output: bool 'true' if username is unique else 'false '
            ///</summary>
            public bool addUser(string user, ref  RichTextBox  textBox1, ref ListBox listBox1)
            {
                  //check is username is present in the userlist 'ArrayList'
                  bool test=userlist.Contains(user) ;
                  if(test)
                  {
                        //if present then Give the message to use and return 'false'
                        textBox1.Text+="This Nick has already been taken, try changing your Nick \n" ;
                        return false ;
                  }
                  else
                  {
                        //user is unique hence add him to the userlist
                
                        userlist.Add(user) ;
                        //add the RichTextBox reference to textboxlist
                        textboxlist.Add(textBox1);
                        //add to existing users list
                        foreach(ListBox lb in listboxlist)
                        {
                              lb.Items.Add(user) ;
                        }
                        //add the ListBox reference to listboxlist
                        listboxlist.Add(listBox1) ;
                        //Send to message only to the client connected
                        textBox1.Text+="Connected to server... \n" ;
                        //send message to everyone .
                        sendMessage(user+" has Joined Chat") ;
                        //add all the usernames in the ListBox of the client
                        foreach(string users in userlist)
                        {
                              listBox1.Items.Add(users) ;
                        }
              
                        return true ;
                  }
      
            }
 
            ///<summary>
            ///      Input: string username
            ///      It is called when the user quits chat
            ///</summary>
            public void removeUser(string user)
            {
                  //check is the user is present in the userlist      
                  try
                  {
                        if(userlist.Contains(user))
                        {
                              //get the position of user in userlist
                              int i=userlist.IndexOf(user) ;
                              //remove user from userlist
                              userlist.Remove(user) ;
                              //remove user's RichTextBox reference from textboxarray
                              textboxlist.RemoveAt(i) ;
                              //remove user's ListBox refrence from listboxarray
                              listboxlist.RemoveAt(i) ;
                              //Inform all users about user quiting
                              sendMessage(user+" has quit Chat") ;
                              //emove the user from all users ListBox
                              foreach(ListBox lb in listboxlist)
                              {
                                    lb.Items.Remove((object)user) ;
                         
                              }
                        }
                  }
                  catch(Exception ed)
                  {
                        Console.WriteLine(ed) ;
                  }
            }
            ///<summary>
            ///      Input: string message
            ///      it sends the message to all users connected to the server
            ///<summary>
            public void sendMessage(string message)
            {
                  //write the message on the server console
                  Console.WriteLine ("Added Message : {0}", message);
                  //for each user connected, send the message to them
                  foreach(RichTextBox rf in textboxlist)
                  {
                        rf.Text+=message+"\n" ;
                  }
        
            }
      }
 
      public class TheServer
      {
 
            public static void Main ()
            {
      
                  int listeningChannel = 1099;
                  // Create a New HTTP Channel that listens on Port listeningChannel
                  // TCPChannel channel = new TCPChannel (listeningChannel);
                  HTTPChannel channel = new HTTPChannel (listeningChannel);
                  // Register the channel with the runtime
                  ChannelServices.RegisterChannel (channel);
                  // Expose the Calculator Object from this Server
                  RemotingServices.RegisterWellKnownType ("Server",
                        "com.icommware.PublishSubscribe.Topic",
                        "Topic.soap",
                        WellKnownObjectMode.Singleton);
                  // Keep the Server running until the user presses enter
                  Console.WriteLine ("The Topic Server is up and running on port {0}", listeningChannel);                  
                  Console.WriteLine ("Press enter to stop the server...");
                  Console.ReadLine ();
            }
      }
}



************ Code End







When I complie this code, it gives me error on two lines:
The messages are as below

error CS0234: The type or namespace name 'WinForms' does not exist in the class or namespace 'System' (are you missing an assembly reference?)

error CS0234: The type or namespace name 'HTTP' does not exist in the class or namespace 'System.Runtime.Remoting.Channels' (are you missing an assembly reference?)




0
alakhan
Asked:
alakhan
  • 6
  • 5
  • 5
1 Solution
 
ozymandiasCommented:
Its System.Runtime.Remoting.Channels.Http....case sensitive.
0
 
ozymandiasCommented:
For using System.WinForms, do you mean using System.Windows.Forms ?
0
 
ozymandiasCommented:
Also, Line 121 should be HttpChannel not HTTPChannel.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
caner_elciCommented:
Here is the fixed code:

using System;
using System.IO;
using System.Collections;
using System.Runtime.Remoting;
using System.Windows.Forms ;   //------------------------------------- error on this line
using System.Runtime.Remoting.Channels.Http;   //---------- error on this line

namespace com.icommware.PublishSubscribe
{
 
      public class Topic : MarshalByRefObject
      {
              ArrayList userlist = new ArrayList() ;
            ArrayList textboxlist = new ArrayList() ;
            ArrayList listboxlist = new ArrayList() ;
            ///<summary>
            ///     Input : string username (by value) and RichTextBox , ListBox (by refrence)
            ///   Output: bool 'true' if username is unique else 'false '
            ///</summary>
            public bool addUser(string user, ref  RichTextBox  textBox1, ref ListBox listBox1)
            {
                  //check is username is present in the userlist 'ArrayList'
                  bool test=userlist.Contains(user) ;
                  if(test)
                  {
                        //if present then Give the message to use and return 'false'
                        textBox1.Text+="This Nick has already been taken, try changing your Nick \n" ;
                        return false ;
                  }
                  else
                  {
                        //user is unique hence add him to the userlist
             
                        userlist.Add(user) ;
                        //add the RichTextBox reference to textboxlist
                        textboxlist.Add(textBox1);
                        //add to existing users list
                        foreach(ListBox lb in listboxlist)
                        {
                              lb.Items.Add(user) ;
                        }
                        //add the ListBox reference to listboxlist
                        listboxlist.Add(listBox1) ;
                        //Send to message only to the client connected
                        textBox1.Text+="Connected to server... \n" ;
                        //send message to everyone .
                        sendMessage(user+" has Joined Chat") ;
                        //add all the usernames in the ListBox of the client
                        foreach(string users in userlist)
                        {
                              listBox1.Items.Add(users) ;
                        }
           
                        return true ;
                  }
     
            }
 
            ///<summary>
            ///     Input: string username
            ///     It is called when the user quits chat
            ///</summary>
            public void removeUser(string user)
            {
                  //check is the user is present in the userlist    
                  try
                  {
                        if(userlist.Contains(user))
                        {
                              //get the position of user in userlist
                              int i=userlist.IndexOf(user) ;
                              //remove user from userlist
                              userlist.Remove(user) ;
                              //remove user's RichTextBox reference from textboxarray
                              textboxlist.RemoveAt(i) ;
                              //remove user's ListBox refrence from listboxarray
                              listboxlist.RemoveAt(i) ;
                              //Inform all users about user quiting
                              sendMessage(user+" has quit Chat") ;
                              //emove the user from all users ListBox
                              foreach(ListBox lb in listboxlist)
                              {
                                    lb.Items.Remove((object)user) ;
                     
                              }
                        }
                  }
                  catch(Exception ed)
                  {
                        Console.WriteLine(ed) ;
                  }
            }
            ///<summary>
            ///     Input: string message
            ///     it sends the message to all users connected to the server
            ///<summary>
            public void sendMessage(string message)
            {
                  //write the message on the server console
                  Console.WriteLine ("Added Message : {0}", message);
                  //for each user connected, send the message to them
                  foreach(RichTextBox rf in textboxlist)
                  {
                        rf.Text+=message+"\n" ;
                  }
       
            }
      }
 
      public class TheServer
      {
 
            public static void Main ()
            {
     
                  int listeningChannel = 1099;
                  // Create a New HTTP Channel that listens on Port listeningChannel
                  // TCPChannel channel = new TCPChannel (listeningChannel);
                  HttpChannel channel = new HttpChannel (listeningChannel);
                  // Register the channel with the runtime
                  System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel (channel);
                  // Expose the Calculator Object from this Server

                  WellKnownServiceTypeEntry srvcEntry = new WellKnownServiceTypeEntry (
                        typeof (com.icommware.PublishSubscribe.Topic), "Topic.soap",
                        WellKnownObjectMode.Singleton);
                  RemotingConfiguration.ApplicationName = "Server";
                  try
                  {
                        RemotingConfiguration.RegisterWellKnownServiceType (srvcEntry);
                  }
                  catch (Exception ex)
                  {
                        Console.WriteLine ("RemoteSystemInfo: Exception : " + ex.Message);                  
                  }

                  // Keep the Server running until the user presses enter
                  Console.WriteLine ("The Topic Server is up and running on port {0}", listeningChannel);                  
                  Console.WriteLine ("Press enter to stop the server...");
                  Console.ReadLine ();
            }
      }
}
0
 
ozymandiasCommented:
You need to include this using statement or line 123 wont compile :

using System.Runtime.Remoting.Channels;
0
 
ozymandiasCommented:
L:ine 126 is all wrong...method doesn't exist.
The closest thing I can find is this :

RemotingConfiguration.RegisterWellKnownServiceType Method (Type, String, WellKnownObjectMode)
0
 
alakhanAuthor Commented:
Hi guys,

Thanks for helping. You ppl have lot of time helped me and I am thakfult to you all.
I tried your solutions but they did not work. I tried to replace HTTP with Http but it is still problem.
I ran the code of caner and it giving error.

I THINK I AM DOING SOMETHING WRONG:
This is site from where I download the code
http://www.c-sharpcorner.com/internet/chat_server.asp
It gives an exe file too: server.exe and a batch file to complie it like this:

csc /debug+ /r:system.dll /r:system.winforms.dll /r:Server.exe /r:System.runtime.remoting.dll /r:System.Drawing.dll  /r:Microsoft.Win32.Interop.dll /out:Server.exe NewServer.cs

When I run this to complie it gave me this error:
error CS0006: Metadata file 'system.winforms.dll' could not be found
error CS0006: Metadata file Microsoft.win32.Interop.dll' could not be found

Any body who give me additional help to develop a chat server or give me some sample code for chat server in dot net in which I can use rich text to draw drawings and some shapes i will give him additional 150 to 200 points

THANKS FOR ALL AGAIN

0
 
caner_elciCommented:
try System.Windows.Forms.dll instead of system.winforms.dll
and remove /r:microsoft.win32.interop.dll
0
 
caner_elciCommented:
try this command to compile:

csc /debug+ /r:system.dll /r:system.windows.forms.dll /r:System.runtime.remoting.dll /r:System.Drawing.dll /out:Server.exe NewServer.cs
0
 
alakhanAuthor Commented:
I tried this command:

csc /debug+ /r:system.dll /r:system.windows.forms.dll /r:System.runtime.remoting.dll /r:System.Drawing.dll /out:Server.exe NewServer.cs


errors comes as below:

NewServer.cs(17,14): error CS0234: The type or namespace name 'WinForms' does not exist in the class or namespace 'System' (are you missing an assembly reference)

NewServer.cs(18,40) .... 'HTTP' ..... 'System.Runtime.Remoting.Channels' .....

NewServer.cs(32,41) : ... 'RichTextBox'      
0
 
caner_elciCommented:
Are you using the code I posted??? I think you are not..
0
 
alakhanAuthor Commented:
Ya I did not use your code. I am sorry It is working now.

I will be very thankful to you if you will explain that what was wrong. As I also have to complie its client too.


Thanks a lot
0
 
caner_elciCommented:
You're welcome.. That sample was written with Framework 1.0, and since 1.1 is a little different, some namespaces and calls should be changed.. For example, System.Winforms namespaces became System.Windows.Forms, etc.. Or, RemotingServices.RegisterWellKnownType is a little bit changed...
0
 
alakhanAuthor Commented:
I am uploading the client problem too. So If you can please fix it too i will be very thankful to you:
its title is
Compiler error due to dot net version difference:
0
 
caner_elciCommented:
Don't you have complete error text?
0
 
alakhanAuthor Commented:
Hi,

I have put question for chat client with similar problem: The details of question is as below:

Question Title: Compiler error due to dot net version difference
Author: alakhan
Points: 100
Date: 04/15/2004 02:07PM PDT


Can any body help me again?

Thanks in advance:
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now