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. Fast possiblity to send data from Server to Client

Fast possiblity to send data from Server to Client

Scheduled Pinned Locked Moved C#
questionsysadmin
5 Posts 2 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.
  • H Offline
    H Offline
    hansipet
    wrote on last edited by
    #1

    Hello, I search for a fast possibility to send data from a server to the client. It should be possible to send the data from one PC to the other. For some other functions the server implements at the moment a remote interface with RegisterWellKnownServiceType... What is the best possibity to send data (in worst case it could be about 1Mb/s) to the client? Best regards Hansjörg

    H H 2 Replies Last reply
    0
    • H hansipet

      Hello, I search for a fast possibility to send data from a server to the client. It should be possible to send the data from one PC to the other. For some other functions the server implements at the moment a remote interface with RegisterWellKnownServiceType... What is the best possibity to send data (in worst case it could be about 1Mb/s) to the client? Best regards Hansjörg

      H Offline
      H Offline
      hansipet
      wrote on last edited by
      #2

      another thing that I have forgotten...the data is allways a instance of the same class Thanks Hansjörg

      1 Reply Last reply
      0
      • H hansipet

        Hello, I search for a fast possibility to send data from a server to the client. It should be possible to send the data from one PC to the other. For some other functions the server implements at the moment a remote interface with RegisterWellKnownServiceType... What is the best possibity to send data (in worst case it could be about 1Mb/s) to the client? Best regards Hansjörg

        H Offline
        H Offline
        Hessam Jalali
        wrote on last edited by
        #3

        Seems you are using Remoting and in .NET remoting you can send streams from server side to client with requesting it from the client area I used it for sending none shared files from the server to client and the speed was far more 1MByte/Sec (but this method is not such a secure one for file sharing!) and ofcourse with sending streams you can send all types of data (so you can send your instances as Data with serializing them on the fly in memory stream and then send the stream to client) I can't give you a complete code because it was part of a bigger project and I must send you lots of code to work but here is the code I wrote for testing it is possible to do this or not sorry the code is somewhat messy (it was for testing puposes only) the share part

        namespace NetTest
        {
        public class RemoteFileBrowser:MarshalByRefObject
        {
        public delegate void EventFireHandler();
        public event EventFireHandler eventFiredFromRemoteObject;

            public RemoteResult GetStream(string path)
            {
                if (!File.Exists(path)) return new RemoteResult();
        
                return new RemoteResult(new FileStream(path, FileMode.Open));
            }
        
            public RemoteResult Failed()
            {
                return new RemoteResult();
            }
        
            public string GetMachineName()
            {
                return Environment.MachineName;
            }
        
            public string GetAuthor()
            {
                if (this.eventFiredFromRemoteObject != null) this.eventFiredFromRemoteObject();
                return "Hessam Jalali";
            }
        
        }
        

        }

        the server side

        class Program
        {
            static void Main(string\[\] args)
            {
                Console.WriteLine("Host Started");
        
                TcpChannel tc = new TcpChannel(50000);
                ChannelServices.RegisterChannel(tc,false);
        
                RemoteFileBrowser rfb = new RemoteFileBrowser();
        
                rfb.eventFiredFromRemoteObject += new RemoteFileBrowser.EventFireHandler(rfb\_eventFiredFromRemoteObject);
                RemotingConfiguration.RegisterWellKnownServiceType(rfb.GetType(), "rfb.rem", WellKnownObjectMode.Singleton);
        
                Console.WriteLine();
                Console.WriteLine("Press any key to Exit...");
                Console.ReadKey();
        
                ChannelServices.UnregisterChannel(tc);
        
            }
        
            static void rfb\_eventFiredFromRemoteObject()
            {
                Console.WriteLine("Event Fired inside");
            }
        }
        

        and the client side

        H 1 Reply Last reply
        0
        • H Hessam Jalali

          Seems you are using Remoting and in .NET remoting you can send streams from server side to client with requesting it from the client area I used it for sending none shared files from the server to client and the speed was far more 1MByte/Sec (but this method is not such a secure one for file sharing!) and ofcourse with sending streams you can send all types of data (so you can send your instances as Data with serializing them on the fly in memory stream and then send the stream to client) I can't give you a complete code because it was part of a bigger project and I must send you lots of code to work but here is the code I wrote for testing it is possible to do this or not sorry the code is somewhat messy (it was for testing puposes only) the share part

          namespace NetTest
          {
          public class RemoteFileBrowser:MarshalByRefObject
          {
          public delegate void EventFireHandler();
          public event EventFireHandler eventFiredFromRemoteObject;

              public RemoteResult GetStream(string path)
              {
                  if (!File.Exists(path)) return new RemoteResult();
          
                  return new RemoteResult(new FileStream(path, FileMode.Open));
              }
          
              public RemoteResult Failed()
              {
                  return new RemoteResult();
              }
          
              public string GetMachineName()
              {
                  return Environment.MachineName;
              }
          
              public string GetAuthor()
              {
                  if (this.eventFiredFromRemoteObject != null) this.eventFiredFromRemoteObject();
                  return "Hessam Jalali";
              }
          
          }
          

          }

          the server side

          class Program
          {
              static void Main(string\[\] args)
              {
                  Console.WriteLine("Host Started");
          
                  TcpChannel tc = new TcpChannel(50000);
                  ChannelServices.RegisterChannel(tc,false);
          
                  RemoteFileBrowser rfb = new RemoteFileBrowser();
          
                  rfb.eventFiredFromRemoteObject += new RemoteFileBrowser.EventFireHandler(rfb\_eventFiredFromRemoteObject);
                  RemotingConfiguration.RegisterWellKnownServiceType(rfb.GetType(), "rfb.rem", WellKnownObjectMode.Singleton);
          
                  Console.WriteLine();
                  Console.WriteLine("Press any key to Exit...");
                  Console.ReadKey();
          
                  ChannelServices.UnregisterChannel(tc);
          
              }
          
              static void rfb\_eventFiredFromRemoteObject()
              {
                  Console.WriteLine("Event Fired inside");
              }
          }
          

          and the client side

          H Offline
          H Offline
          hansipet
          wrote on last edited by
          #4

          I'm not sure at the moment if this works. The main purpose of this application is to send the log data to other connected clients. For that I don't wan't to poll allways the server.. but maybe that there is possibility to use the stream! do you know if it is possible to deserialize objectes allways from the same stream? Best regards and many thanks

          H 1 Reply Last reply
          0
          • H hansipet

            I'm not sure at the moment if this works. The main purpose of this application is to send the log data to other connected clients. For that I don't wan't to poll allways the server.. but maybe that there is possibility to use the stream! do you know if it is possible to deserialize objectes allways from the same stream? Best regards and many thanks

            H Offline
            H Offline
            Hessam Jalali
            wrote on last edited by
            #5

            hansipet wrote:

            do you know if it is possible to deserialize objectes allways from the same stream?

            If you mean one stream for all Yes it is possible but you must set the pointers of the stream manually eachtime by yourself for preventing errors.and ofcourse you need some implementation for preventing asynchronous calls from clients for requesting the stream and update requests from the server on the that. and if you mean same stream as serialized in request the answer is yes again and this time you just need to set the pointers to first of the stream with using methods like seek

            hansipet wrote:

            I don't wan't to poll allways the server

            if you said that because of the singleton it can be singleCall so after calling and disposing the stream the resources from server side will release and there would be no problem. but if your Log files are not so huge I think creating a class as LogDataHolder and mark it as serializible then return it as value to clients would be a better idea. good luck

            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