Solved

Whats wrong with code?

Posted on 2004-04-15
16
646 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now