— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet439/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   435   436   437   438   439   440   441   442   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

InputStreamReader stream = new InputStreamReader(chatSocket.getInputStream());
2
Make an InputStreamReader chained to the Socket’s 
low-level (connection) input stream
InputStreamReader is a ‘bridge’ between a low-
level byte stream (like the one coming from the 
Socket) and a high-level character stream (like 
the BufferedReader we’re after as our top of 
the chain stream).
Client
Socket’s input stream 
(we don’t need to know 
the actual class)
011010011
bytes from server
source
chained to
All we have to do is ASK the socket for 
an input stream! It’s a low-level connection 
stream, but we’re just gonna chain it to 
something more text-friendly.
Data on the 
server
characters
destination
InputStreamReader
chained to
buffered 
characters
BufferedReader
converted to characters
buffered characters
Server
input and output streams 
to and from the Socket 
connections 
reading from a 
socket


networking 
and
threads
you are here
4
479
We didn’t use PrintWriter in the last chapter, we used BufferedWriter. We have 
a choice here, but when you’re writing one String at a time, PrintWriter is the 
standard choice. And you’ll recognize the two key methods in PrintWriter, 
print() and println()! Just like good ol’ System.out.
To write data to a Socket, use a 
PrintWriter
Socket chatSocket = new Socket(“127.0.0.1”, 5000);
1
Make a Socket connection to the server
writer.println(“message to send”);
writer.print(“another message”);
3
Write (print) something 
println() adds a new line at the end of what it sends.
print() doesn’t add the new line.
this part’s the same as it was 
on the 
opposite page -- to write to the 
server, we still have to connect 
to it.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   435   436   437   438   439   440   441   442   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish