Solved

Whats wrong with code?

Posted on 2004-04-15
16
649 Views
Last Modified: 2007-12-19
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
Comment
Question by:alakhan
  • 6
  • 5
  • 5
16 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 10834260
Its System.Runtime.Remoting.Channels.Http....case sensitive.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 10834273
For using System.WinForms, do you mean using System.Windows.Forms ?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 10834329
Also, Line 121 should be HttpChannel not HTTPChannel.
0
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.

 
LVL 4

Accepted Solution

by:
caner_elci earned 150 total points
ID: 10834337
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
 
LVL 15

Expert Comment

by:ozymandias
ID: 10834340
You need to include this using statement or line 123 wont compile :

using System.Runtime.Remoting.Channels;
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 10834365
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
 

Author Comment

by:alakhan
ID: 10834617
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
 
LVL 4

Expert Comment

by:caner_elci
ID: 10834653
try System.Windows.Forms.dll instead of system.winforms.dll
and remove /r:microsoft.win32.interop.dll
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10834681
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
 

Author Comment

by:alakhan
ID: 10834844
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
 
LVL 4

Expert Comment

by:caner_elci
ID: 10835044
Are you using the code I posted??? I think you are not..
0
 

Author Comment

by:alakhan
ID: 10835590
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
 
LVL 4

Expert Comment

by:caner_elci
ID: 10836228
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
 

Author Comment

by:alakhan
ID: 10836947
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
 
LVL 4

Expert Comment

by:caner_elci
ID: 10837662
Don't you have complete error text?
0
 

Author Comment

by:alakhan
ID: 10842670
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Coding C# in Linux 8 120
use of unassigned local variable 'id' 6 53
Hey!! 5 37
Change to file doesn't show up 16 50
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question