— Scott McNealy, Sun Microsystems Chairman, President and ceo



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

return adviceList[random];
}

public static void main(String[] args) {
DailyAdviceServer server = new DailyAdviceServer();
server.go();
}
}
DailyAdviceServer code
This program makes a ServerSocket and waits for client requests. When it gets 
a client request (i.e. client said new Socket() for this application), the server 
makes a new Socket connection to that client. The server makes a PrintWriter 
(using the Socket’s output stream) and sends a message to the client.
remember the imports
daily advice comes from this array
ServerSocket makes this server 
application ‘listen’ for client requests 
on port 4242 on the machine this 
code is running on.
The server goes into a permanent loop
waiting for (and servicing) client requests
the accept method blocks (just sits there) until a 
request comes in, and then the method returns a 
Socket (on some anonymous port) for communicating 
with the client
now we use the Socket connection to the client to 
make a PrintWriter and send it (println()) a String 
advice message. Then we close the Socket because 
we’re done with this client. 
writing a 
server
(remember, these Strings 
were word-wrapped by 
the code editor. Never 
hit return in the middle 
of a String!)


networking 
and
threads
you are here
4
485
 BULLET POINTS
ß
Client and server applications communicate over a Socket 
connection.
ß
A Socket represents a connection between two applications 
which may (or may not) be running on two different physical 
machines.
ß
A client must know the IP address (or domain name) and 
TCP port number of the server application.
ß
A TCP port is a 16-bit unsigned number assigned to a 
specific server application. TCP port numbers allow different 
clients to connect to the same machine but communicate 
with different applications running on that machine.
ß
The port numbers from 0 through 1023 are reserved for 
‘well-known services’ including HTTP, FTP, SMTP, etc.
ß
A client connects to a server by making a Server socket 

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   440   441   442   443   444   445   446   447   ...   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