— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet449/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   445   446   447   448   449   450   451   452   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

} // close SendButtonListener inner class

 public static void main(String[] args) {
new SimpleChatClientA().go();
}
 } 
// close outer class
imports for the streams (java.io), 
Socket (java.net) and the GUI 
stuff
build the GUI, nothing new 
here, and nothing related to 
networking or I/O.
This is where we make the Socket 
and the PrintWriter (it’s called 
from the go() method right before 
displaying the app GUI)
Now we actually do the writing. 
Remember, the writer is chained to 
the input stream from the Socket, so 
whenever we do a println(), it goes 
over the network to the server!
we’re using localhost so 
you can test the client 
and server on one machine
If you want to try this now, type in 
the Ready-bake chat server code 
listed at the end of this chapter . 
First, start the server in one terminal. 
Next, use another terminal to start 
this client.


488
 
chapter 15
Version Two: send 
and receive
The Server sends a message to all 
client participants, as soon as the 
message is received by the server. 
When a client sends a message, it 
doesn’t appear in the incoming 
message display area until the 
server sends it to everyone.
outgoing message
incoming 
messages
Big Question: 
HOW do you get messages from the server?
Should be easy; when you set up the networking make an input stream as well 
(probably a BufferedReader). Then read messages using readLine().
Bigger Question: 
WHEN do you get messages from the server?
Think about that. What are the options?
Pros: Well, it’s do-able
Cons: How does the server know what you’ve seen and what you haven’t? The server 
would have to store the messages, rather than just doing a distribute-and-forget each time 
it gets one. And why 20 seconds? A delay like this affects usability, but as you reduce the 
delay, you risk hitting your server needlessly. Inefficient.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   445   446   447   448   449   450   451   452   ...   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