亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch18.htm

?? 21天學會用java開發網絡游戲 這對于 想學java編程的人會很有用
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
the host using the HTTP protocol behind the scenes. Figure 18.1
illustrates how ports and protocols work.
<P>
<A HREF="f18-1.gif" ><B>Figure 18.1 : </B><I>A conceptual look at protocols and ports.</I></A>
<P>
All standard service assignments are given port values below 1024.
This means that ports above 1024 are considered available for
custom communications, such as those required by a network game
implementing its own protocol. Keep in mind, however, that other
types of custom communication also take place above port 1024,
so you might have to try a few different ports to find an unused
one.
<H2><A NAME="TheClientServerParadigm"><B><FONT SIZE=5 COLOR=#FF0000>The
Client/Server Paradigm</FONT></B></A></H2>
<P>
So far, I've managed to explain a decent amount of Internet networking
fundamentals while dodging a major issue: the client/server paradigm.
You've no doubt heard of clients and servers before, but you might
not fully understand their importance in regard to the Internet.
Well, it's time to remedy that situation, because you won't be
able to get much done in Java without understanding how clients
and servers work.
<P>
The client/server paradigm involves thinking of computing in terms
of a client, who is essentially in need of some type of information,
and a server, who has lots of information and is just waiting
to hand it out. Typically, a client connects to a server and queries
for certain information. The server goes off and finds the information
and then returns it to the client. It might sound as though I'm
oversimplifying things here, but for the most part I'm not; conceptually,
client/server computing is as simple as a client asking for information
and a server returning it.
<P>
In the context of the Internet, clients are typically computers
attached to the Internet looking for information, whereas servers
are typically larger computers with certain types of information
available for the clients to retrieve. The Web itself is made
up of a bunch of computers that act as Web servers; they have
vast amounts of HTML pages and related data available for people
to retrieve and browse. Web clients are those of us who connect
to the Web servers and browse through the Web pages. In this way,
Netscape Navigator is considered client Web software. Take a look
at Figure 18.2 to get a better idea of the client/server arrangement.
<P>
<A HREF="f18-2.gif" ><B>Figure 18.2 : </B><I>A Web server with multiple clients.</I></A>
<P>
At this point, you might be wondering how the client/server strategy
impacts Java game programming. Well, Java games run within the
confines of a Web page, which is accessed via client Web browser
software such as Netscape Navigator. Each player in a network
Java game is running the game within a Web browser, which means
that each player is acting as a client. When the players attempt
to communicate with each other, you are left with Web clients
trying to transfer information among themselves, which can't happen
directly. The solution is for the clients (players) to communicate
with each other through the server; the server effectively acts
as a middleman routing information among the clients. Don't worry
if this sounds kind of strange; you'll learn the details later
today.
<H2><A NAME="Sockets"><B><FONT SIZE=5 COLOR=#FF0000>Sockets</FONT></B></A>
</H2>
<P>
One of Java's major strong suits as a programming language is
its wide range of network support. Java has this advantage because
it was developed with the Internet in mind. The result is that
you have lots of options in regard to network programming in Java.
Even though there are many network options, Java network game
programming uses a particular type of network communication known
as sockets.
<P>
A <I>socket</I> is a software abstraction for an input or output
medium of communication.
<P>
Java performs all of its low-level network communication through
sockets. Logically, sockets are one step lower than ports; you
use sockets to communicate through a particular port. So a socket
is a communication channel enabling you to transfer data through
a certain port. Check out Figure 18.3, which shows communication
taking place through multiple sockets on a port.
<P>
<A HREF="f18-3.gif" ><B>Figure 18.3 : </B><I>Socket communication on a port.</I></A>
<P>
This figure brings up an interesting point about sockets: data
can be transferred through multiple sockets for a single port.
Java provides socket classes to make programming with sockets
much easier. Java sockets are broken down into two types: stream
sockets and datagram sockets.
<H3><A NAME="StreamSockets"><B>Stream Sockets</B></A></H3>
<P>
A <I>stream socket</I>, or connected socket, is a socket over
which data can be transmitted continuously.
<P>
By continuously, I don't necessarily mean that data is being sent
all the time, but that the socket itself is active and ready for
communication all the time. Think of a stream socket as a dedicated
network connection, in which a communication medium is always
available for use. The benefit of using a stream socket is that
information can be sent with less worry about when it will arrive
at its destination. Because the communication link is always &quot;live,&quot;
data is generally transmitted immediately after you send it. This
method of communication is the method you will use tomorrow to
write a sample network game, NetConnect4.
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
A practical example of data being sent through a streaming mechanism is RealAudio, a technology that provides a way to listen to audio on the Web as it is being transmitted in real time.</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<P>
Java supports streamed socket programming primarily through two
classes: <TT><FONT FACE="Courier">Socket</FONT></TT> and <TT><FONT FACE="Courier">ServerSocket</FONT></TT>.
The <TT><FONT FACE="Courier">Socket</FONT></TT> class provides
the necessary overhead to facilitate a streamed socket client,
and the <TT><FONT FACE="Courier">ServerSocket</FONT></TT> class
provides the core functionality for a server. Here is a list of
some of the more important methods implemented in the <TT><FONT FACE="Courier">Socket</FONT></TT>
class:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">Socket(String host, int port)<BR>
Socket(InetAddress address, int port)<BR>
synchronized void close()<BR>
InputStream getInputStream()<BR>
OutputStream getOutputStream()</FONT></TT>
</BLOCKQUOTE>
<P>
The first two methods listed are actually constructors for the
<TT><FONT FACE="Courier">Socket</FONT></TT> class. The host computer
you are connecting the socket to is specified in the first parameter
of each constructor; the difference between the two constructors
is whether you specify the host using a string name or an <TT><FONT FACE="Courier">InetAddress</FONT></TT>
object. The second parameter is an integer specifying the port
you want to connect to. The <TT><FONT FACE="Courier">close</FONT></TT>
method is used to close a socket. The <TT><FONT FACE="Courier">getInputStream</FONT></TT>
and <TT><FONT FACE="Courier">getOutputStream</FONT></TT> methods
are used to retrieve the input and output streams associated with
the socket.
<BLOCKQUOTE>
<TT><FONT FACE="Courier">The ServerSocket class handles the other
end of socket communication in a client/server scenario. Here
are a few of the more useful methods defined in the ServerSocket
class:<BR>
ServerSocket(int port)<BR>
ServerSocket(int port, int count)<BR>
Socket accept()<BR>
void close()</FONT></TT>
</BLOCKQUOTE>
<P>
The first two methods are the constructors for <TT><FONT FACE="Courier">ServerSocket</FONT></TT>,
which both take a port number as the first parameter. The <TT><FONT FACE="Courier">count</FONT></TT>
parameter in the second constructor specifies a timeout period
for the server to automatically &quot;listen&quot; for a client
connection. This is the distinguishing factor between the two
constructors; the first version doesn't listen for a client connection,
whereas the second version does. If you use the first constructor,
you must specifically tell the server to wait for a client connection.
You do this by calling the <TT><FONT FACE="Courier">accept</FONT></TT>
method, which blocks program flow until a connection is made.
The <TT><FONT FACE="Courier">close</FONT></TT> method simply closes
the server socket.
<P>
You might be thinking that the socket classes seem awfully simple.
In fact, they are simple, which is a good thing. Most of the actual
code facilitating communication via sockets is handled through
the input and output streams connected to a socket. In this way,
the communication itself is handled independently of the network
socket connection. This might not seem like a big deal at first,
but it is crucial in the design of the socket classes; after you've
created a socket, you connect an input or output stream to it
and then forget about the socket.
<P>
The <TT><FONT FACE="Courier">Socket</FONT></TT> and <TT><FONT FACE="Courier">ServerSocket</FONT></TT>
classes are the classes you'll use a little later today to build
a simple networking applet. You'll get to see how easy it is to
communicate using Java and sockets.
<H3><A NAME="DatagramSockets"><B>Datagram Sockets</B></A></H3>
<P>
The other type of socket supported by Java is the datagram socket.
Unlike stream sockets, in which the communication is akin to a
live network, a datagram socket is more akin to a dial-up network,
in which the communication link isn't continuously active.
<P>
A <I>datagram socket</I> is a socket over which data is bundled
into packets and sent without requiring a &quot;live&quot; connection
to the destination computer.
<P>
Because of the nature of the communication medium involved, datagram
sockets aren't guaranteed to transmit information at a particular
time, or even in any particular order. The reason datagram sockets
perform this way is that they don't require an actual connection
to another computer; the address of the target computer is just
bundled with the information being sent. This bundle is then sent
out over the Internet, leaving the sender to hope for the best.
<P>
On the receiving end, the bundles of information can be received
in any order and at any time. For this reason, datagrams also
include a sequence number that specifies which piece of the puzzle
each bundle corresponds to. The receiver waits to receive the
entire sequence, in which case it puts them back together to form
a complete information transfer. As you might be thinking, datagram
sockets are less than ideal for network game programming, simply
because of the implied time delays and sequencing complexities.
<H2><A NAME="AReusableSocketClass"><B><FONT SIZE=5 COLOR=#FF0000>A
Reusable Socket Class</FONT></B></A></H2>
<P>
You've now learned enough about network theory and the Java networking
support to write some code. Before you can think in terms of writing
network game code, however, you need to develop some code that
helps facilitate the core communications necessary for a game.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区国产| 国产在线一区二区| 日本一区二区三区视频视频| 欧美日产在线观看| 欧美一区二区三区电影| 777午夜精品免费视频| 91成人国产精品| 欧美日韩激情一区| 欧美一区二区三区四区高清| 日韩一区二区在线观看视频| 日韩视频在线永久播放| 精品国产区一区| 久久精品日产第一区二区三区高清版| 亚洲精品一区二区三区香蕉| 久久综合国产精品| 国产女人aaa级久久久级 | 亚洲国产精品久久久久婷婷884| 亚洲免费色视频| 亚洲国产成人tv| 蜜臀av一区二区在线观看| 国产资源精品在线观看| 国产盗摄一区二区| 色乱码一区二区三区88| 欧美欧美欧美欧美| 国产清纯美女被跳蛋高潮一区二区久久w | 69av一区二区三区| 欧美成人综合网站| 国产精品久久久久久久久免费丝袜 | av高清不卡在线| 欧洲视频一区二区| 日韩美女在线视频| 综合亚洲深深色噜噜狠狠网站| 亚洲一级电影视频| 另类综合日韩欧美亚洲| 成人avav影音| 4438x成人网最大色成网站| 久久你懂得1024| 亚洲福利视频一区| 国产成人aaa| 欧美一区二区成人| 亚洲视频电影在线| 国产伦精品一区二区三区免费迷| 色婷婷亚洲一区二区三区| 欧美成人女星排名| 亚洲成a人片综合在线| 高清不卡在线观看| 91麻豆精品久久久久蜜臀| 国产精品二三区| 寂寞少妇一区二区三区| 91极品视觉盛宴| 中文字幕国产精品一区二区| 欧美aaaaaa午夜精品| 色综合一区二区三区| 久久综合色之久久综合| 舔着乳尖日韩一区| 91色视频在线| 国产网站一区二区三区| 美女视频第一区二区三区免费观看网站| www.欧美日韩国产在线| 亚洲精品一区二区三区影院 | 国产suv精品一区二区三区| 91精品国产一区二区三区蜜臀| 国产精品理论片在线观看| 精品一区二区三区日韩| 91精品国产综合久久福利 | 男女男精品视频网| 欧美日韩一区精品| 亚洲午夜国产一区99re久久| 色婷婷精品大视频在线蜜桃视频| 国产亚洲精品bt天堂精选| 国产综合色视频| 欧美mv和日韩mv的网站| 毛片基地黄久久久久久天堂| 欧美午夜精品电影| 蜜臀久久久久久久| 欧美裸体bbwbbwbbw| 亚洲一级不卡视频| 欧美日韩精品二区第二页| 亚洲大片精品永久免费| 欧美无砖砖区免费| 亚洲国产精品一区二区www在线| 欧美亚洲综合网| 一区二区三区四区不卡在线| 色视频一区二区| 亚洲午夜精品在线| 91精品久久久久久蜜臀| 美女高潮久久久| 国产色婷婷亚洲99精品小说| 国产成人夜色高潮福利影视| 国产精品免费久久久久| a级高清视频欧美日韩| 成人欧美一区二区三区黑人麻豆| 日本精品免费观看高清观看| 亚洲电影中文字幕在线观看| 91精品欧美福利在线观看| 韩国中文字幕2020精品| 国产精品乱码人人做人人爱| 99久久99久久精品国产片果冻| 亚洲一区在线观看视频| 欧美日韩国产经典色站一区二区三区| 亚洲成人在线网站| 日韩一区二区三区精品视频 | 成人黄色一级视频| 夜夜嗨av一区二区三区四季av| 91精品啪在线观看国产60岁| 在线成人免费观看| 国模一区二区三区白浆| 国产精品久久久久久福利一牛影视 | 欧美夫妻性生活| 国产精品一区二区x88av| 亚洲欧美激情在线| xnxx国产精品| 色域天天综合网| 国产在线一区二区综合免费视频| 亚洲免费在线电影| 久久久久久久久岛国免费| 91美女福利视频| 国产一区二区三区电影在线观看 | 欧美系列日韩一区| 国产精品乡下勾搭老头1| 亚洲一区二区三区影院| 久久综合久久综合九色| 欧美视频中文一区二区三区在线观看| 国产在线播放一区三区四| 亚洲综合成人在线视频| 久久综合视频网| 欧美日韩精品是欧美日韩精品| 成人av在线看| 美女精品自拍一二三四| 一区二区三区在线播| 日本一区二区三区国色天香| 欧美一区二区播放| 欧美日本一区二区在线观看| 成人午夜激情在线| 韩国av一区二区三区四区| 午夜精品久久一牛影视| 日韩毛片视频在线看| 国产欧美精品一区二区三区四区 | 综合色天天鬼久久鬼色| 欧美精品一区二区在线播放| 欧美日韩大陆一区二区| 色综合中文字幕| 99riav久久精品riav| 国产高清精品网站| 激情图区综合网| 久久99久久99精品免视看婷婷 | 欧美一区三区四区| 精品视频在线视频| 91视频免费观看| 91毛片在线观看| 色哟哟一区二区| 色天使色偷偷av一区二区| 91网页版在线| 在线观看日韩国产| 欧美亚日韩国产aⅴ精品中极品| 在线亚洲高清视频| 欧美日韩免费不卡视频一区二区三区 | 久久久www成人免费无遮挡大片| 日韩欧美一级特黄在线播放| 91精品在线一区二区| 欧美美女一区二区在线观看| 欧美日韩成人综合| 欧美一个色资源| 26uuu久久天堂性欧美| 国产日韩精品一区二区三区| 国产网红主播福利一区二区| 中文字幕亚洲综合久久菠萝蜜| 成人欧美一区二区三区小说 | 国产.欧美.日韩| jlzzjlzz国产精品久久| 在线精品视频小说1| 9191成人精品久久| 26uuu欧美日本| 国产精品免费看片| 亚洲一区av在线| 久久se精品一区精品二区| 国产一区二区网址| www.亚洲激情.com| 欧美电影在哪看比较好| 日韩一区二区三| 国产精品理论片| 日韩国产欧美在线观看| 国产精品一级在线| 欧美少妇xxx| 精品国产91洋老外米糕| 亚洲你懂的在线视频| 日本欧美一区二区三区乱码| 国产乱码精品1区2区3区| 日本高清无吗v一区| 日韩精品一区二区三区中文不卡| 国产午夜久久久久| 亚洲高清免费观看| 国产精品18久久久久| 欧美日韩一区二区不卡| 久久久久久一二三区| 亚洲午夜羞羞片| 国产99一区视频免费| 666欧美在线视频| 亚洲品质自拍视频| 国产麻豆精品久久一二三|