'Java socket output has delayed first message
I'm having a very strange problem with sockets in Java. It could be caused because of my lack of knowledge about sockets but here it is:
I'm using a socket to connect to an IRC-server. The connection is made perfectly and I receive all the messages the IRC-server is sending me. When the connection is made, I authenticate to the server and I start a seperate thread to receive what the server sends me. In that thread I send a message once when connected to make the program join a certain channel.
boolean joined = false;
while ((line = getInput().readLine()) != null) {
if (!joined) {
getOutput().println("JOIN #Random");
getOutput().println("JOIN #Modnar");
if (line.contains("JOIN :#Random")) {
joined = true;
System.out.println("JOINED #Random= true");
}
}
At the end of this method I call getOutput().flush();
Now when I'm trying to send a message TO the IRCserver via the client I'm writing, it seems to take ages before the first message gets through. When it finally get's through everything seems to be working fine. All following messages are handled immediately. It's just that first message I'm sending after being connected and having joined that channel that takes long.
The method I'm using to send a message to the server is very simple:
public void sendToServer(String input) {
getOutput().println(input);
getOutput().flush();
}
Is there anyone who has a clue why the first message is taking so long to transmit to the server while all the following (after the first finally arrived) go well?
If it might be worth mentioning: I'm using a Tomcat6 for my servlets on which I make the connection and an UnrealIRCd as IRC-server. The messages are send to the servlet via AJAX. (But the sending to the server seems to go well, since the System.out I'm doing when a message is send is printed immediately in my Tomcat-log, so the delay is in the socket OR in the IRC-server..)
If more info is needed, I shall try to provide it, since this might look quite complicated like this..
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
