• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

use of bufferedwriter.newline() in server/client code

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

--------------------------------------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------

on the server side,if i don't write newline() ,why is nothing printed on client side even though i use flush()?
 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the client is probably executing the readLine(), which means it will keep waiting until it sees something that signals the end of the line.

Incidentally it's a very bad idea to have those empty catch blocks. If something goes wrong and you do get an exception, the empty catch block will silently catch the exception, without giving you any useful information about what happened. Which makes it very difficult to detect the problem, much less fix it. I suggest replacing the catch blocks with something like:
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
vinit mav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but why is it so that if i write bufferedwriter.close() instead of bufferedwriter.newline() and bufferedwriter.flush() , then the client successfully prints even though the line is not ending?
thank you very much........
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vinit,

readline() behaves like Mike have specified. It blocks until it runs into "\n", "\r", "\r\n", or EOF.
However it still keeps data already read in. It just won't be returned until function comes across one of previously specified delimiters.

You might want to check out:
readLine()
and
Source which says:


464: // We only want to return null when no characters were read before
465: // EOF.



HTH

Welcome to JavaRanch!
 
vinit mav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Kacper....
 
Mike Simmons
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
vinit mav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i visited a site whatismyipaddress.com and it showed my ip ,but when i put this for the ip address in this program,it didn't work.
why is this program unable to run on internet?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe because your computer is behind a firewall or a router which does NAT (network address translation), which causes your computer to have a different IP address in the local network than on the outside Internet.
 
vinit mav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried port forwarding but it still isn't working?
is there a solution for this?
 
vinit mav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does the server/client chat application only work on lan and not on internet???
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic