資源描述:
《20132155邢超超13計(jì)科3班(java實(shí)驗(yàn)十)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、2015/2016學(xué)年第一學(xué)期《Java程序設(shè)計(jì)》實(shí)驗(yàn)報(bào)告十班級(jí)計(jì)科三班學(xué)號(hào)20132155姓名邢超超實(shí)驗(yàn)時(shí)間12.17實(shí)驗(yàn)地點(diǎn)東實(shí)驗(yàn)樓2-204實(shí)驗(yàn)成績(jī)一、實(shí)驗(yàn)題目1、驗(yàn)證InetAddress類的使用。2、驗(yàn)證URL類訪問(wèn)WWW資源。3、驗(yàn)證Socket類客戶端程序設(shè)計(jì)方法。4、驗(yàn)證ServerSocket類服務(wù)器端程序設(shè)計(jì)方法。5、驗(yàn)證Datagram客戶端、服務(wù)器端程序設(shè)計(jì)方法。6、驗(yàn)證基于客戶/服務(wù)器模式的分布式程序設(shè)計(jì)方法。二、實(shí)驗(yàn)?zāi)康膶W(xué)習(xí)和掌握網(wǎng)絡(luò)程序設(shè)計(jì)的基本方法。三、實(shí)驗(yàn)過(guò)程1、2、四、實(shí)驗(yàn)心得五、源程序1.importjavax.swing
2、.*;importjava.awt.*;importjava.net.*;importjava.awt.event.*;publicclassLocalHostextendsJApplet{InetAddresshostAddr=null;publicvoidstart(){try{hostAddr=InetAddress.getLocalHost();}catch(UnknownHostExceptione){System.out.println(e.getMessage());}repaint();}publicvoidpaint(Graphicsg){g
3、.drawString("Hostname/ip"+hostAddr.toString(),10,30);}}2.importjava.net.*;importjava.io.*;publicclassOpenStreamTest{publicstaticvoidmain(String[]args){try{URLyahoo=newURL("http://www.yahoo.com/");DataInputStreamdis=newDataInputStream(yahoo.openStream());StringinputLine;while((inputL
4、ine=dis.readLine())!=null){System.out.println(inputLine);}dis.close();}catch(MalformedURLExceptionme){System.out.println("MalformedURLException:"+me);}catch(IOExceptionioe){System.out.println("IOException:"+ioe);}}}3.importjava.net.*;importjava.io.*;publicclassConnectionTest{publics
5、taticvoidmain(String[]args){try{URLyahoo=newURL("http://www.yahoo.com/");URLConnectionyahooConnection=yahoo.openConnection();DataInputStreamdis=newDataInputStream(yahoo.openStream());StringinputLine;while((inputLine=dis.readLine())!=null){System.out.println(inputLine);}dis.close();}
6、catch(MalformedURLExceptionme){System.out.println("MalformedURLException:"+me);}catch(IOExceptionioe){System.out.println("IOException:"+ioe);}}}4.importjava.net.*;importjava.io.*;publicclassWebConnect{publicstaticvoidmain(String[]args){try{Socketconnection=newSocket(args[0],80);Syst
7、em.out.println("Connectionestablished");System.out.println("LocalConnectionInformation");System.out.println("taddress:"+connection.getLocalAddress());System.out.println("tport:"+connection.getLocalPort());System.out.println("RemateConnectionInformation");System.out.println("taddr
8、ess:"+connection.ge