예제 #1
0
        static void Main(string[] args)
        {
            var fluentConfig = FluentConfig.Begin()
                               .StartRemotingOn("localhost")  //no port given = use any free port
                               .Build();

            using (var system = ActorSystem.Create("MyClient", fluentConfig))
            {
                var chatClient = system.ActorOf(Props.Create <ChatClientActor>());
                var tmp        = system.ActorSelection("akka.tcp://MyServer@localhost:8081/user/ChatServer");
                chatClient.Tell(new ConnectRequest()
                {
                    Username = "******",
                });

                while (true)
                {
                    var input = Console.ReadLine();
                    if (input.StartsWith("/"))
                    {
                        var parts = input.Split(' ');
                        var cmd   = parts[0].ToLowerInvariant();
                        var rest  = string.Join(" ", parts.Skip(1));

                        if (cmd == "/nick")
                        {
                            chatClient.Tell(new NickRequest
                            {
                                NewUsername = rest
                            });
                        }
                    }
                    else
                    {
                        chatClient.Tell(new SayRequest()
                        {
                            Text = input,
                        });
                    }
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            //            var config = ConfigurationFactory.ParseString(@"
            //akka {
            //    log-config-on-start = on
            //    stdout-loglevel = DEBUG
            //    loglevel = ERROR
            //    actor {
            //        provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
            //
            //        debug {
            //          receive = on
            //          autoreceive = on
            //          lifecycle = on
            //          event-stream = on
            //          unhandled = on
            //        }
            //    }
            //
            //    remote {
            //		log-received-messages = on
            //		log-sent-messages = on
            //        #log-remote-lifecycle-events = on
            //
            //        #this is the new upcoming remoting support, which enables multiple transports
            //       helios.tcp {
            //            transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
            //		    applied-adapters = []
            //		    transport-protocol = tcp
            //		    port = 8081
            //		    hostname = 0.0.0.0 #listens on ALL ips for this machine
            //            public-hostname = localhost #but only accepts connections on localhost (usually 127.0.0.1)
            //        }
            //        log-remote-lifecycle-events = INFO
            //    }
            //
            //}
            //");
            var fluentConfig = FluentConfig.Begin()
                               .StdOutLogLevel(LogLevel.DebugLevel)
                               .LogConfigOnStart(true)
                               .LogLevel(LogLevel.ErrorLevel)
                               .LogLocal(
                receive: true,
                autoReceive: true,
                lifecycle: true,
                eventStream: true,
                unhandled: true
                )
                               .LogRemote(
                lifecycleEvents: LogLevel.DebugLevel,
                receivedMessages: true,
                sentMessages: true
                )
                               .StartRemotingOn("localhost", 8081)
                               .Build();

            using (var system = ActorSystem.Create("MyServer", fluentConfig))
            {
                var server = system.ActorOf <ChatServerActor>("ChatServer");

                Console.ReadLine();
            }
        }