English 中文(简体)
服务器没有直接回应我的指挥
原标题:Server does not respond directly to my commands
  • 时间:2012-04-11 12:02:00
  •  标签:
  • java
  • netty

首先,我承认我是新鲜事,我很可能被遗忘在某个地方选择正确的变量,但我的Googling却失败了我,我不知道要做什么,因此我希望得到一些帮助。

我以安全Chat的例子为基础,可以在这里找到:

而且,我所做的区别只是安卡拉卡特施尔。 更确切地说,在信息中:

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    // Convert the message to a string
    String request = (String) e.getMessage();

    System.out.println("Message recieved: " + request);

    if (request.equalsIgnoreCase("clients")) {
        channels.write("We currently have: " + channels.size() + " clients");
    } else if (request.toLowerCase().equals("koko"))
        for (Channel c : channels) {
            if (c == e.getChannel())
                c.write("HELLO WORLD");
        }
    else {
        // Then send it to all channels, but the current one.
        for (Channel c : channels)
            if (c != e.getChannel())
                c.write("[" + e.getChannel().getRemoteAddress() + "] " + request + "
");
            else
                c.write("[you] " + request + "
");

    }

    if (request.equalsIgnoreCase("bye"))
        e.getChannel().close();
}

如果我发出一个正常的信息,即广播,一切都会奏效。 但是,如果我发出指挥,如<clients,那么我就得不到回应,直到我再次进入并发出空洞信息。 首先,我得到回复。

 C:Device ManagerApplication ServerExamp
 lesSecureChatSecureChatClientin>java -jar client.jar 127.0.0.1 8080
 UNKNOWN SERVER CERTIFICATE: CN=securechat.example.netty.gleamynode.net, OU=Contr
 ibutors, O=The Netty Project, L=Seongnam-si, ST=Kyunggi-do, C=KR
 Welcome to Electus secure chat service!
 Your session is protected by TLS_DHE_RSA_WITH_AES_128_CBC_SHA cipher suite
 You are the 1th user
 koko<ENTER>
 <PRESS ENTER AGAIN>
 HELLO WORLD[you]
 clients<ENTER>
 <AND ENTER ONCE AGAIN>
 We currently have: 1 clients[you]

我不理解,不希望的是,进入纽顿两度。 这似乎非常不合逻辑,令人不快。 在Telnet Example,我没有问题。

感谢你时间。

Regards, Aldrian.

最佳回答

这是你仅挑出一个小小细节,并评估一切的羞辱时代之一。

if (request.equalsIgnoreCase("clients")) {
    channels.write("We currently have: " + channels.size() + " clients /n"); // Forgot /n here
} else if (request.toLowerCase().equals("koko"))
    for (Channel c : channels) {
        if (c == e.getChannel())
            c.write("HELLO WORLD /n"); // <- Forgot /n here as well
    }
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...