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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? ch9.htm

?? JAVA Developing Professional JavaApplets
?? HTM
?? 第 1 頁(yè) / 共 5 頁(yè)
字號(hào):
ioe)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(&quot;Errorin SimpleWebServer: &quot; + ioe);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;public static void ServiceClient(Socketclient)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throws IOException<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataInputStreaminbound = null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataOutputStreamoutbound = null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Acquire the streams for IO<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inbound= new DataInputStream( client.getInputStream());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outbound= new DataOutputStream( client.getOutputStream());<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//Format the output (response header and tiny HTML document)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringBufferbuffer = PrepareOutput();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StringinputLine;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while((inputLine = inbound.readLine()) != null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//If end of HTTP request, send the response<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( inputLine.equals(&quot;&quot;) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outbound.writeBytes(buffer.toString());<BR>&nbsp;&nbsp;&nbsp;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&nbsp;}</TT></BLOCKQUOTE><HR><P>Servers do not actively create connections. Instead, they passivelylisten for a client connect request and then provide their services.Servers are created with a constructor from the ServerSocket class.The following line creates a server socket and binds it to port80:<BLOCKQUOTE><TT>ServerSocket serverSocket = new ServerSocket(80,5);</TT></BLOCKQUOTE><P>The first parameter is the port number on which the server shouldlisten. The second parameter is optional. The API documentationindicates that this parameter is a listen time, but in traditionalsockets programming the listen function's second parameter isthe listen stack depth. As it turns out, this is also true forthe second constructor parameter. A server can receive connectrequests from many clients at the same time, but each call mustbe processed one at a time. The <I>listen stack</I> is a queueof unanswered connect requests. The above code instructs the socketdriver to maintain the last five connect requests. If the constructoromits the listen stack depth, a default value of <TT>50</TT>is used.<P>Once the socket is created and listening for connections, incomingconnections are created and placed on the listen stack. The <TT>accept()</TT>method is called to lift individual connections off the stack:<BLOCKQUOTE><TT>Socket clientSocket = serverSocket.accept();</TT></BLOCKQUOTE><P>This method returns a connected client socket used to conversewith the caller. No conversations are ever conducted over theserver socket itself. Instead, the server socket will spawn anew socket in the <TT>accept()</TT>method. The server socket is still open and queuing new connectionrequests.<P>Like the client socket, the next step is to create an input andoutput stream:<BLOCKQUOTE><TT>DataInputStream inbound = new DataInputStream(clientSocket.getInputStream() );<BR>DataOutputStream outbound = new DataOutputStream( clientSocket.getOutputStream());</TT></BLOCKQUOTE><P>Normal I/O operations can now be performed by using the newlycreated streams. This server waits for the client to send a blankline before sending its response. When the conversation is finished,the server closes the streams and the client socket. At this point,the server tries to accept more calls. What happens when thereare no calls waiting in the queue? The method will wait for oneto arrive. This behavior is known as <I>blocking</I>. The <TT>accept()</TT>method will block the server thread from performing any othertasks until a new call arrives. When five connects have been serviced,the server exits by closing its server socket. Any queued callswill be canceled.<P>All servers follow the same basic script:<OL><LI>Create the server socket and begin listening.<LI>Call the <TT>accept()</TT> methodto get new connections.<LI>Create input and output streams for the returned socket.<LI>Conduct the conversation based on the agreed protocol.<LI>Close the client streams and socket.<LI>Go back to step 2, or continue to step 7.<LI>Close the server socket.</OL><P>Figure 9.1<B> </B>summarizes the steps needed for client/serverconnection-oriented applications.<P><A HREF="f9-1.gif" ><B>Figure 9.1:</B> <I>Client and server connection-oriented applications.</I></A><H3><A NAME="IterativeandConcurrentServers">Iterative and ConcurrentServers</A></H3><P>The application just presented is known as an <I>iterative server</I>because the code accepts a client connection and completely processesit before it will accept another connection. More complex serversare concurrent. Instead of accepting connections and immediatelyprocessing them, a <I>concurrent server</I> spawns a new threadto process each new request, so it seems as though the serveris processing many requests simultaneously. All commercial Webservers are concurrent servers.<H3><A NAME="JavaDatagramClasses">Java Datagram Classes</A></H3><P>Unlike connection-oriented classes, the datagram versions of theclient and server behave in nearly identical manners-the onlydifference occurs in implementation. The same class is used forboth client and server halves. The following lines create clientand server datagram sockets:<BLOCKQUOTE><TT>DatagramSocket serverSocket = new DatagramSocket(4545 );<BR>DatagramSocket clientSocket = new DatagramSocket();</TT></BLOCKQUOTE><P>The server specifies its port using the lone constructor parameter<TT>4545</TT>. Since the client willcall the server, the client can use any available port. The omittedconstructor parameter in the second call instructs the operatingsystem to assign the next available port number. The client couldhave requested a specific port, but the call would fail if someother socket had already bound itself to that port. It's betternot to specify a port unless the intent is to be a server.<P>Since streams can't be acquired for communication, how do youtalk to a DatagramSocket? The answer lies in the DatagramPacketclass.<H4>Receiving Datagrams</H4><P>The DatagramPacket class is used to receive and send data overDatagramSocket classes. The packet class contains connection informationas well as the data. As was explained earlier, datagrams are self-containedtransmission units. The DatagramPacket class encapsulates theseunits. The following lines receive data from a datagram socket:<BLOCKQUOTE><TT>DatagramPacket packet = new DatagramPacket(newbyte[512], 512);<BR>clientSocket.receive(packet);</TT></BLOCKQUOTE><P>The constructor for the packet needs to know where to place thereceived data. A 512-byte buffer was created and passed to theconstructor as the first parameter. The second constructor parameterwas the size of the buffer. Like the <TT>accept()</TT>method in the ServerSocket class, the <TT>receive()</TT>method will block until data is available.<H4>Sending Datagrams</H4><P>Sending datagrams is really very simple; all that's needed isa complete address. Addresses are created and tracked by usingthe InetAddress class. This class has no public constructors,but it does contain several static methods that can be used tocreate an instance of the class. The following list shows thepublic methods that create InetAddress class instances:<BR><P><CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%><TR VALIGN=TOP><TD WIDTH=541><I>Public InetAddress Creation Methods</I></TD></TR><TR VALIGN=TOP><TD WIDTH=541><BLOCKQUOTE><TT>InetAddress getByName(String host);<BR>InetAddress[] getAllByName(String host);<BR>InetAddress getLocalHost();</TT></BLOCKQUOTE></TD></TR></TABLE></CENTER><P><P>Getting the local host is useful for informational purposes, butonly the first two methods are actually used for sending packets.Both <TT>getByName()</TT> and <TT>getAllByName()</TT>require the name of the destination host. The first method merelyreturns the first match it finds. The second method is neededbecause a computer can have more than one address. When this occurs,the computer is said to be <I>multi-homed</I>. The computer hasone name, but multiple ways to reach it.<P>All the creation methods are marked as static. They must be calledas follows:<BLOCKQUOTE><TT>InetAddress addr1 = InetAddress.getByName(&quot;merlin&quot;);<BR>InetAddress addr2[] = InetAddress.getAllByName(&quot;merlin&quot;);<BR>InetAddress addr3 = InetAddress.getLocalHost();</TT></BLOCKQUOTE><P>Any of these calls can throw an UnknownHostException. If a computeris not connected to a Domain Name Server (DNS) or if the hostis really not found, an exception will be thrown. If a computerdoes not have an active TCP/IP configuration, then <TT>getLocalHost()</TT>is likely to fail with this exception as well.<P>Once an address is determined, datagrams can be sent. The followinglines transmit a String to a destination socket:<BLOCKQUOTE><TT>String toSend = &quot;This is the datato send!&quot;);<BR>byte[] sendbuf = new byte[ toSend.length() ];<BR>toSend.getBytes( 0, toSend.length(), sendbuf, 0 );<BR>DatagramPacket sendPacket = new DatagramPacket( sendbuf, sendbuf.length,addr, port);<BR>clientSocket.send( sendPacket );</TT></BLOCKQUOTE><P>First, the string must be converted to a byte array. The <TT>getBytes()</TT>method takes care of the conversion. Next, a new DatagramPacketinstance must be created. Notice the two extra parameters at theend of the constructor. Since this will be a send packet, theaddress and port of the destination must also be placed into thepacket. An applet may know the address of its server, but howdoes a server know the address of its client? Remember that adatagram is like an envelope-it has a return address. When anypacket is received, the return address can be extracted from thepacket by using <TT>getAddress()</TT>and <TT>getPort()</TT>. This is howa server would respond to a client packet:<BLOCKQUOTE><TT>DatagramPacket sendPacket = new DatagramPacket(sendbuf, sendbuf.length,<BR>&nbsp;&nbsp;&nbsp;&nbsp;recvPacket.getAddress(), recvPacket.getPort());<BR>serverSocket.send( sendPacket );</TT></BLOCKQUOTE><P>Unlike connection-oriented operation, datagram servers are actuallyless complicated than the datagram client.<H4>Datagram Servers</H4><P>The basic script for datagram servers is as follows:<OL><LI>Create the datagram socket on a specific port.<LI>Call receive to wait for incoming packets.<LI>Respond to received packets according to the agreed protocol.<LI>Go back to step 2, or continue to step 5.<LI>Close the datagram socket.</OL><P>Listing 9.3 shows a simple datagram echo server. It will echoback any packets it receives.<HR><BLOCKQUOTE><B>Listing 9.3. A simple datagram echo server.<BR></B></BLOCKQUOTE><BLOCKQUOTE><TT>import java.io.*;<BR>import java.net.*;<BR>

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美最猛性xxxxx直播| 国产午夜精品一区二区三区视频| av网站一区二区三区| 国产乱码精品一区二区三区av| 久久99日本精品| 黄色日韩网站视频| 国产一区二区精品久久99| 国产一区二区三区| 丁香五精品蜜臀久久久久99网站| 国产成人在线视频网站| 国产成人一级电影| av不卡一区二区三区| 欧美久久久一区| 欧美挠脚心视频网站| 91精品国产aⅴ一区二区| 91麻豆精品国产91久久久久久 | 免费观看成人鲁鲁鲁鲁鲁视频| 日韩精品一二三四| 喷白浆一区二区| 国产一区二区免费在线| 福利一区二区在线观看| a在线播放不卡| 欧洲精品在线观看| 日韩无一区二区| 久久久久久综合| 中文字幕日本不卡| 亚洲成av人片在线观看无码| 久久成人18免费观看| 国产精品中文字幕日韩精品| 粉嫩在线一区二区三区视频| www.性欧美| 欧美日韩国产片| 久久色成人在线| **性色生活片久久毛片| 午夜激情久久久| 国产一区二区三区四| 99久久er热在这里只有精品15| 欧美亚洲国产一区二区三区| 欧美刺激脚交jootjob| 中文字幕国产一区| 午夜欧美在线一二页| 国产一区二区视频在线播放| 91免费精品国自产拍在线不卡| 欧美日韩国产一区二区三区地区| 精品久久久久av影院 | 国产精品综合视频| 色偷偷久久一区二区三区| 日韩一卡二卡三卡| 国产精品美女视频| 日韩国产欧美在线观看| 成人一区二区三区在线观看| 欧美日韩国产一二三| 国产亚洲成aⅴ人片在线观看| 亚洲资源中文字幕| 国产在线精品一区二区三区不卡| 一本久久精品一区二区| 欧美videos中文字幕| 亚洲一区成人在线| 国产黄色精品网站| 欧美一级艳片视频免费观看| 国产精品国产三级国产普通话三级 | 久久综合国产精品| 一区二区三区日韩欧美精品| 狠狠色狠狠色综合系列| 欧美色视频一区| 国产无人区一区二区三区| 天天综合色天天| 色婷婷激情一区二区三区| 国产日产欧美一区| 老司机免费视频一区二区| 日本黄色一区二区| 中国av一区二区三区| 久久国产精品99久久人人澡| 欧美性视频一区二区三区| 国产精品久久久久四虎| 精品在线你懂的| 26uuu色噜噜精品一区二区| 亚洲bt欧美bt精品777| 一本一本大道香蕉久在线精品 | 国产在线观看一区二区 | 亚洲午夜久久久久久久久久久 | 欧美日韩色综合| 亚洲视频免费看| 成人一区二区三区视频 | 亚洲在线视频网站| 94-欧美-setu| 亚洲欧洲精品成人久久奇米网| 精品一区二区三区视频在线观看 | 欧美精品三级在线观看| 亚洲欧美日韩中文播放 | 国产亚洲欧美中文| 激情综合色综合久久| 日韩亚洲欧美成人一区| 亚洲18女电影在线观看| 欧美三级韩国三级日本三斤| 亚洲精品va在线观看| 91社区在线播放| 亚洲色图视频免费播放| 99久久夜色精品国产网站| 国产精品色哟哟| kk眼镜猥琐国模调教系列一区二区| 久久亚洲综合色| 国产曰批免费观看久久久| 精品国精品国产| 精久久久久久久久久久| 久久综合色天天久久综合图片| 另类中文字幕网| 精品国产第一区二区三区观看体验| 久久99久久久久久久久久久| 欧美电影免费观看高清完整版| 轻轻草成人在线| 欧美精品一区二区精品网| 狠狠久久亚洲欧美| 国产午夜精品福利| eeuss国产一区二区三区| 国产精品盗摄一区二区三区| 91女神在线视频| 亚洲成va人在线观看| 欧美一卡在线观看| 精品无人码麻豆乱码1区2区 | 国产老女人精品毛片久久| 国产欧美日韩另类一区| 不卡视频免费播放| 一区二区三区在线视频免费| 欧美日韩在线综合| 日本不卡一区二区| 精品成人免费观看| 在线精品视频一区二区三四| 亚洲国产精品天堂| 欧美tickling挠脚心丨vk| 国产美女娇喘av呻吟久久| 国产精品久久久久9999吃药| 在线观看网站黄不卡| 蜜臀国产一区二区三区在线播放| 欧美大片在线观看一区二区| 国产不卡视频一区二区三区| 亚洲欧洲三级电影| 欧美电影影音先锋| 国产中文字幕一区| 亚洲欧美激情插| 日韩欧美国产一区二区三区| 成人黄动漫网站免费app| 一区二区高清免费观看影视大全 | 久久先锋资源网| 色综合久久综合中文综合网| 偷偷要91色婷婷| 国产日产欧美精品一区二区三区| 在线影院国内精品| 精品一区二区三区香蕉蜜桃| 亚洲视频免费观看| 欧美白人最猛性xxxxx69交| 成人免费视频一区二区| 日韩国产精品大片| 亚洲色图欧洲色图婷婷| 日韩一区二区三区三四区视频在线观看 | 精品一区二区三区不卡| 国产精品久久久久久一区二区三区| 欧美私模裸体表演在线观看| 国产真实精品久久二三区| 亚洲激情自拍视频| 国产日韩三级在线| 欧美一区午夜精品| 91免费版在线看| 韩国女主播一区二区三区| 亚洲最色的网站| 欧美激情综合在线| 欧美一区二区福利在线| 91高清视频在线| 成人免费视频caoporn| 日韩av一区二区三区| 亚洲色图色小说| 国产欧美日韩视频一区二区| 日韩欧美在线网站| 欧美色区777第一页| 波多野结衣一区二区三区| 久久精品噜噜噜成人av农村| 亚洲免费在线观看| 国产精品欧美一区喷水| 精品国产青草久久久久福利| 欧美日本乱大交xxxxx| 波多野洁衣一区| 国产99久久久国产精品潘金 | 欧美日韩一区二区三区视频| www.成人在线| 国产不卡在线视频| 国内精品自线一区二区三区视频| 肉色丝袜一区二区| 夜夜嗨av一区二区三区中文字幕| 国产精品久久午夜| 欧美高清在线视频| 久久久欧美精品sm网站| 欧美哺乳videos| 中文字幕不卡一区| 国产亚洲成年网址在线观看| 亚洲精品一区二区三区在线观看| 88在线观看91蜜桃国自产| 欧美色涩在线第一页| 欧美午夜不卡在线观看免费| 日本精品一区二区三区高清 | 精品国产伦一区二区三区免费|