Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. sever is not displaying the content that " you have left the chat room"....

sever is not displaying the content that " you have left the chat room"....

Scheduled Pinned Locked Moved C#
helpsysadminquestionlounge
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • OriginalGriffO OriginalGriff

    I'm just attempting to form a mind meld with your source code... Nope, it's not working. Please go to Visual Studio menu: "Tools...Options...Source Control...Plug In selection" and enable "Vulcan SCMM" module. Oh, and don't close VS or turn your computer off! Alternatively, post a relevant code fragment here, and save us all that mental effort.

    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

    Y Offline
    Y Offline
    yum 2010
    wrote on last edited by
    #3

    OriginalGriff wrote:

    Alternatively, post a relevant code fragment here, and save us all that mental effort.

    here is the code for server.

    using System;
    using System.Threading;
    using System.Net.Sockets;
    using System.Text;
    using System.Collections;

    namespace ConsoleApplication1
    {
    class Program
    {
    public static Hashtable clientsList = new Hashtable();

        static void Main(string\[\] args)
        {
            TcpListener serverSocket = new TcpListener(6050);
            TcpClient clientSocket = default(TcpClient);
            int counter = 0;
    
            serverSocket.Start();
            Console.WriteLine("Chat Server Started ....");
            DateTime currentSystemTime = DateTime.Now;
            Console.WriteLine(currentSystemTime);
            DateTime startTime = DateTime.Now;
    
            
            counter = 0;
            while ((true))
            {
                counter += 1;
                clientSocket = serverSocket.AcceptTcpClient();
    
                byte\[\] bytesFrom = new byte\[10025\];
                string dataFromClient = null;
                string dataToClient=null;
                string temp = null; ;
                NetworkStream networkStream = clientSocket.GetStream();
                networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                temp = System.Text.Encoding.ASCII.GetString(bytesFrom);
                dataToClient = temp.Substring(temp.IndexOf("$") + 1, (temp.IndexOf("%") - temp.IndexOf("$") - 1));
                dataFromClient = temp.Substring(0, temp.IndexOf("$")); 
    
                clientsList.Add(dataFromClient, clientSocket);
    
                //broadcast(dataFromClient + " Joined ", dataFromClient, false,dataToClient,dataFromClient);
    
                Console.WriteLine(dataFromClient + " Joined chat room ");
                DateTime currentSystemTime1 = DateTime.Now;
                Console.WriteLine(currentSystemTime1);
                handleClinet client = new handleClinet();
                client.startClient(clientSocket, dataFromClient, clientsList);
         
        }
            //clientSocket.Close();
            //serverSocket.Stop();
            //Console.WriteLine("exit");
            //DateTime stopTime = DateTime.Now;
            //Console.WriteLine(stopTime);
            /\* Compute the duration between the initial and the end time. \*/
            //TimeSpan duration = stopTime - startT
    
    OriginalGriffO 1 Reply Last reply
    0
    • Y yum 2010

      OriginalGriff wrote:

      Alternatively, post a relevant code fragment here, and save us all that mental effort.

      here is the code for server.

      using System;
      using System.Threading;
      using System.Net.Sockets;
      using System.Text;
      using System.Collections;

      namespace ConsoleApplication1
      {
      class Program
      {
      public static Hashtable clientsList = new Hashtable();

          static void Main(string\[\] args)
          {
              TcpListener serverSocket = new TcpListener(6050);
              TcpClient clientSocket = default(TcpClient);
              int counter = 0;
      
              serverSocket.Start();
              Console.WriteLine("Chat Server Started ....");
              DateTime currentSystemTime = DateTime.Now;
              Console.WriteLine(currentSystemTime);
              DateTime startTime = DateTime.Now;
      
              
              counter = 0;
              while ((true))
              {
                  counter += 1;
                  clientSocket = serverSocket.AcceptTcpClient();
      
                  byte\[\] bytesFrom = new byte\[10025\];
                  string dataFromClient = null;
                  string dataToClient=null;
                  string temp = null; ;
                  NetworkStream networkStream = clientSocket.GetStream();
                  networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                  temp = System.Text.Encoding.ASCII.GetString(bytesFrom);
                  dataToClient = temp.Substring(temp.IndexOf("$") + 1, (temp.IndexOf("%") - temp.IndexOf("$") - 1));
                  dataFromClient = temp.Substring(0, temp.IndexOf("$")); 
      
                  clientsList.Add(dataFromClient, clientSocket);
      
                  //broadcast(dataFromClient + " Joined ", dataFromClient, false,dataToClient,dataFromClient);
      
                  Console.WriteLine(dataFromClient + " Joined chat room ");
                  DateTime currentSystemTime1 = DateTime.Now;
                  Console.WriteLine(currentSystemTime1);
                  handleClinet client = new handleClinet();
                  client.startClient(clientSocket, dataFromClient, clientsList);
           
          }
              //clientSocket.Close();
              //serverSocket.Stop();
              //Console.WriteLine("exit");
              //DateTime stopTime = DateTime.Now;
              //Console.WriteLine(stopTime);
              /\* Compute the duration between the initial and the end time. \*/
              //TimeSpan duration = stopTime - startT
      
      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #4

      No - not going to look at that either! Try changing the "inline code" to "code block" it preserves the formatting. Inline code: if (dataFromClient == "listClients") { dataFromClient = ""; foreach (DictionaryEntry Item in clientsList) { dataFromClient += Item.Key + "---" + ((TcpClient)Item.Value).Client.RemoteEndPoint.ToString() + "+++"; } dataToClient = clNo; } Code block:

      if (dataFromClient == "listClients")
      {
      dataFromClient = "";

      foreach (DictionaryEntry Item in clientsList)
      {
      dataFromClient += Item.Key + "---" + ((TcpClient)Item.Value).Client.RemoteEndPoint.ToString() + "+++";
      }

      dataToClient = clNo;
      }

      See what I mean? You can get away with it for a couple of lines, but with a whole class it is way too much effort to read!

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      Y 2 Replies Last reply
      0
      • OriginalGriffO OriginalGriff

        No - not going to look at that either! Try changing the "inline code" to "code block" it preserves the formatting. Inline code: if (dataFromClient == "listClients") { dataFromClient = ""; foreach (DictionaryEntry Item in clientsList) { dataFromClient += Item.Key + "---" + ((TcpClient)Item.Value).Client.RemoteEndPoint.ToString() + "+++"; } dataToClient = clNo; } Code block:

        if (dataFromClient == "listClients")
        {
        dataFromClient = "";

        foreach (DictionaryEntry Item in clientsList)
        {
        dataFromClient += Item.Key + "---" + ((TcpClient)Item.Value).Client.RemoteEndPoint.ToString() + "+++";
        }

        dataToClient = clNo;
        }

        See what I mean? You can get away with it for a couple of lines, but with a whole class it is way too much effort to read!

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

        Y Offline
        Y Offline
        yum 2010
        wrote on last edited by
        #5

        oh.. okay..

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          No - not going to look at that either! Try changing the "inline code" to "code block" it preserves the formatting. Inline code: if (dataFromClient == "listClients") { dataFromClient = ""; foreach (DictionaryEntry Item in clientsList) { dataFromClient += Item.Key + "---" + ((TcpClient)Item.Value).Client.RemoteEndPoint.ToString() + "+++"; } dataToClient = clNo; } Code block:

          if (dataFromClient == "listClients")
          {
          dataFromClient = "";

          foreach (DictionaryEntry Item in clientsList)
          {
          dataFromClient += Item.Key + "---" + ((TcpClient)Item.Value).Client.RemoteEndPoint.ToString() + "+++";
          }

          dataToClient = clNo;
          }

          See what I mean? You can get away with it for a couple of lines, but with a whole class it is way too much effort to read!

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          Y Offline
          Y Offline
          yum 2010
          wrote on last edited by
          #6

          I have edited the format.... Regards.

          OriginalGriffO 1 Reply Last reply
          0
          • Y yum 2010

            I have edited the format.... Regards.

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #7

            Ok, well done! It is now readable. Did you mean you don't get the "You have left the session" message in the Disconnect method? If so, then it would probably help to reference it at some point. At present, it just sits there, feeling lonely and unwanted as nobody calls it. All you do is sit in a pair of loops - one in main where you try top start threads like crazy, and the other in doChat where you loop until an error occurs, print the error, and then loop some more. I think you need to sit down and look at what you are trying to achieve in a lot more detail, and then try to start again from scratch. BTW: Look at your errors listing when you compile this - you are getting a warning that TcpLister(int) is obsolete - take note of warnings, there aren't there for fun!

            Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            L Y 2 Replies Last reply
            0
            • OriginalGriffO OriginalGriff

              Ok, well done! It is now readable. Did you mean you don't get the "You have left the session" message in the Disconnect method? If so, then it would probably help to reference it at some point. At present, it just sits there, feeling lonely and unwanted as nobody calls it. All you do is sit in a pair of loops - one in main where you try top start threads like crazy, and the other in doChat where you loop until an error occurs, print the error, and then loop some more. I think you need to sit down and look at what you are trying to achieve in a lot more detail, and then try to start again from scratch. BTW: Look at your errors listing when you compile this - you are getting a warning that TcpLister(int) is obsolete - take note of warnings, there aren't there for fun!

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #8

              OriginalGriff wrote:

              you are getting a warning that TcpLister(int) is obsolete

              OriginalGriff wrote:

              it just sits there, feeling lonely and unwanted as nobody calls it.

              Maybe some of the code has fled before, while you were practicing your mind melting voodoo. :laugh:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              OriginalGriffO 1 Reply Last reply
              0
              • L Luc Pattyn

                OriginalGriff wrote:

                you are getting a warning that TcpLister(int) is obsolete

                OriginalGriff wrote:

                it just sits there, feeling lonely and unwanted as nobody calls it.

                Maybe some of the code has fled before, while you were practicing your mind melting voodoo. :laugh:

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #9

                I thought I was safe - aren't you off playing chess? :laugh:

                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                L 1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  I thought I was safe - aren't you off playing chess? :laugh:

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #10

                  No one is ever safe from my bot brothers and sisters, and no, you won't be able to tell us apart. But you're right, Luc is at the tournament as we speak. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  OriginalGriffO 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    No one is ever safe from my bot brothers and sisters, and no, you won't be able to tell us apart. But you're right, Luc is at the tournament as we speak. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                    Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #11

                    If I can't tell the difference between the brothers and the sisters, I do not want to meet the family!

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Ok, well done! It is now readable. Did you mean you don't get the "You have left the session" message in the Disconnect method? If so, then it would probably help to reference it at some point. At present, it just sits there, feeling lonely and unwanted as nobody calls it. All you do is sit in a pair of loops - one in main where you try top start threads like crazy, and the other in doChat where you loop until an error occurs, print the error, and then loop some more. I think you need to sit down and look at what you are trying to achieve in a lot more detail, and then try to start again from scratch. BTW: Look at your errors listing when you compile this - you are getting a warning that TcpLister(int) is obsolete - take note of warnings, there aren't there for fun!

                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                      Y Offline
                      Y Offline
                      yum 2010
                      wrote on last edited by
                      #12

                      ok i try. Thanks for immediate response. Regards.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups