Send text to serversocket after connecting to it

I have a problem that I can't send text to ChatServer. My code: ... try { socket.connect(address); System.out.println("Successfully connected to server!"); Thread fromServerToConsole = new TelnetThread(socket.getInputStream(), System.out); Thread fromConsoleToServer = new TelnetThread(System.in, socket.getOutputStream()); fromConsoleToServer.setDaemon(true); fromServerToConsole.start(); fromConsoleToServer.start(); fromServerToConsole.join(); socket.close(); } catch() ... Where in this try block should I put something like `socket.getOutputStream().write("mystring".bytes())` if I want to send this text "mystring" to the SocketServer after connecting to it? I tried to put this everywhere and it always didn't work, to send "mystring" I always had to press Enter in console of this client (console is for sending messages from console to the server). And the "mystring" was also printed to client's console, but it has to be printed only on the server's side. I need to send "mystring" not from console, but automatically after connecting socket to the server. Please help. Thanks.
Sounds like you need to send a line terminator as well.

以上就是Send text to serversocket after connecting to it的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏