— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

 Let me rephrase the problem: how can 
you make a server that can handle multiple 
clients concurrently??? This would never 
work for a chat server, for instance.
A:
Ah, that’s simple, really. Use separate 
threads, and give each new client Socket to a 
new thread. We’re just about to learn how to 
do that!


486
 
chapter 15
Writing a Chat Client
We’ll write the Chat client application in two stages. First we’ll 
make a send-only version that sends messages to the server but 
doesn’t get to read any of the messages from other participants 
(an exciting and mysterious twist to the whole chat room 
concept).
Then we’ll go for the full chat monty and make one that both 
sends and receives chat messages.
Version One: send-only
public class SimpleChatClientA {

JTextField outgoing;
PrintWriter writer;
Socket sock;
public void go() {
// make gui and register a listener with the send button
// call the setUpNetworking() method

private void setUpNetworking() {
// make a Socket, then make a PrintWriter
// assign the PrintWriter to writer instance variable
}
public class SendButtonListener implements ActionListener {
public void actionPerformed(ActionEvent ev) {
// get the text from the text field and 
// send it to the server using the writer (a PrintWriter)
}
} // close SendButtonListener inner class
} // close outer class
Code outline
Type a message, then press ‘Send’ 
to send it to the server. We 
won’t get any messages 
FROM the 
server in this version, so there’s 
no scrolling text area.

Download 40,57 Mb.

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