Writing messages to client socket using DataOutputStream to Server Socket only sent after closing the Client Socket why?

后端 未结 2 330
醉话见心
醉话见心 2021-01-21 11:04

I had a Socket-Client programming in Java . I am using DataOutputStream to send messages to the Server Socket . Sometimes writed messages on DataOutputstream was not sent to the

相关标签:
2条回答
  • 2021-01-21 11:24

    You have posted too much code, but 99 times out of 100 in these cases where you only see the data after the stream / program has closed your problem is that you are never flushing the data after it is written

    0 讨论(0)
  • 2021-01-21 11:32

    Have you tried calling SetSockOption with TCP_NODELAY?

    • http://docs.oracle.com/javase/6/docs/api/java/net/SocketOptions.html

    • http://www.ibm.com/developerworks/linux/library/l-hisock/index.html

    • http://en.wikipedia.org/wiki/Nagle%27s_algorithm

    0 讨论(0)
提交回复
热议问题