— Scott McNealy, Sun Microsystems Chairman, President and ceo


Socket s = new Socket(“127.0.0.1”, 4200)



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

Socket s = new Socket(“127.0.0.1”, 4200);
ß
Once connected, a client can get input and output streams 
from the socket. These are low-level ‘connection’ streams. 
sock.getInputStream();
ß
To read text data from the server, create a BufferedReader, 
chained to an InputStreamReader, which is chained to the 
input stream from the Socket.
ß
InputStreamReader is a ‘bridge’ stream that takes in 
bytes and converts them to text (character) data. It’s used 
primarily to act as the middle chain between the high-level 
BufferedReader and the low-level Socket input stream.
ß
To write text data to the server, create a PrintWriter chained 
directly to the Socket’s output stream. Call the print() or 
println() methods to send Strings to the server.
ß
Servers use a ServerSocket that waits for client requests on 
a particular port number.
ß
When a ServerSocket gets a request, it ‘accepts’ the request 
by making a Socket connection with the client.
HeadFirst: 
Can you tell us the difference between a ServerSocket 
and a plain old Socket?
ServerSocket:
You’re serious? As a ServerSocket, I AM the 
server. Without me, the application is just a piece of code running 
inside a JVM with no way for any clients to connect.
HeadFirst: 
But don’t regular Sockets connect to the outside 
world? Isn’t that what a socket is for? To connect?
ServerSocket: 
Yeah but you’re missing the point here—a regular 
Socket can only request connections, it can’t accept connections. It 
can call out, but if nobody’s at the other end to get the request, the 
client’s Socket request will fail. Spectacularly, I might add.
HeadFirst: 
What do you mean “more senior”?
ServerSocket: 
I’ve been in the spec since the very beginning! 
Back in version 1.0, when entity beans were considered “optional”. 
Me, though, I was considered essential. And cool. And then in the 
2.0 spec, they add MessageDrivenBeans who don’t even do much. 
It’s hard for me to be upset about EntityBeans because they work so 
hard, what with the database and everything, but come on – Mes-
sageDrivenBeans don’t do anything except wait for the digital UPS 
guy to show up with a message. Half they time they don’t even do 
anything except turn around and hand it someone else to do the 
real work. So they can run back to their inflatable mattress and 
unbrella drinks.

Download 40,57 Mb.

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