.


:




:

































 

 

 

 


InetAddress address, int port)




DatagramPacket(byte[] buf, int offset, int length)

DatagramPacket(byte[] buf, int offset, int length,

InetAddress address, int port)

DatagramPacket(byte[] buf, int offset, int length,

SocketAddress address)

DatagramPacket(byte[] buf, int length,

SocketAddress address)

, . .

DatagramSocket , . send(DatagramPacket pac), receive(DatagramPacket pac).

/* # 9: UDP : Sender.java */

package chapt15;

import java.io.*;

import java.net.*;

public class Sender {

public static void main(String[] args) {

try {

byte [] data = new byte [1000];

DatagramSocket s = new DatagramSocket();

InetAddress addr =

InetAddress.getLocalHost();

/* toxic.mp3 */

FileInputStream fr =

new FileInputStream(

new File("toxic.mp3"));

DatagramPacket pac;

 

while (fr.read(data)!= -1) {

//

pac = new DatagramPacket(data, data.length, addr, 8033);

s.send(pac); //

}

fr.close();

System. out. println(" ");

} catch (UnknownHostException e) {

//

e.printStackTrace();

} catch (SocketException e) {

//

e.printStackTrace();

} catch (FileNotFoundException e) {

//

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}

/* # 10: UDP: Recipient.java */

package chapt15;

import java.io.*;

import java.net.*;

public class Recipient {

public static void main(String[] args) {

File file = new File("toxic2.mp3");

System. out. println(" ...");

try { //

acceptFile (file, 8033, 1000);

} catch (IOException e) {

e.printStackTrace();

}

}

private static void acceptFile (File file, int port,

int pacSize) throws IOException {

byte data[] = new byte[pacSize];

DatagramPacket pac =

new DatagramPacket(data, data.length);

DatagramSocket s = new DatagramSocket(port);

FileOutputStream os =

new FileOutputStream(file);

try {

/* : 10
, */

s.setSoTimeout(60000);

while (true) {

s.receive(pac);

os.write(data);

os.flush();

}

} catch (SocketTimeoutException e) {

//

os.close();

System. out. println(

" , ");

}

}

}

15

/ :

1. .

2. , .

3. . , . .

4. .

5. . .

6. .

7. , on-line.

8. . , .

9. .

10. .

11. 21.

12. . - () . .

13. , IP .

14. . , TCP, . .

15. . , .

B

4 . , .

15

15.1.

socket, :

Socket socket = new Socket("host", 23);

1) POP3;

2) FTP;

3) TCP/IP;

4) IPX;

5) UDP.

15.2.

, URL :

String url = new String("http://bsu.iba.by");

1) Socket content = new
Socket(new URL(url)).connect();

2) Object content = new URL(url).getContent();

3) String content = new URLHttp(url).getString();

4) Object content = new

URLConnection(url).getContent();

5) String content = new
URLConnection(url).connect().

15.3.

?

1) getDocumentBase();

2) getCodeBase();

3) getURLAddress();

4) getCodeAddress();

5) getURLBase().

15.4.

:

Socket s = new Socket("bsu.iba.by", 8080);

1) IOException;

2) MalformedURLException;

3) UnknownHostException;

4) UnknownURLException;

5) UnknownPortException.

15.5.

:

Socket s = null;

ServerSocket server = new ServerSocket(8080);

s = server.accept();

PrintStream p = new PrintStream(s.getOutputStream());

p.print("!");

"!" ?

1) p.flush();

2) p.close();

3) s.flush();

4) s.close();

5) .

 
16

XML & Java

XML (Extensible Markup Language ) W3C , . XML . , (, .). .

XML SGML. XML ( , ), XHTML, SOAP, RSS, MathML.

XML , . -, , .. , . , namespace, XML ( RDF, microformat) (mixed content) XML , ( ).

XML. , (human-readable). , : <name>Java SE 6</name> <name/>. : <?xml version="1.0"?><book> <title>title</title></book><book/>

XML- (root element document element). , . XML, HTML <HTML>.

<?xml version="1.0"?> <book><caption>C++</book></caption> , . caption. HTML . <?xml version="1.0"?> <book><author>Petrov</book>

. , <author/>. HTML ,

(case-sensitive),
.. , <author>, <Author>, <AuToR> XML:

<author>Petrov</Author>

- . HTML .

, :

<book dateOfIssue=09/09/2007 title=JAVA in Belarus/>

L .

: <FORM method=POST action=index.jsp>

XML- :

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE students SYSTEM "students.dtd">

<students>

<student login="mit" faculty="mmf">

<name>Mitar Alex</name>

<telephone>2456474</telephone>

<address>

<country>Belarus</country>

<city>Minsk</city>

<street>Kalinovsky 45</street>

</address>

</student>

<student login="pus" faculty="mmf">

<name>Pashkun Alex</name>

<telephone>3453789</telephone>

<address>

<country>Belarus</country>

<city>Brest</city>

<street>Knorina 56</street>

</address>

</student>

</students>

, XML. .

XML- , XML- (), . , <city>. , / , </city>. (content) , , () .

XML- , . , XML <? ?> , target ().

:

<?xml-stylesheet type="text/xsl" href="book.xsl"?>

, (stylesheet) book.xsl.

XML , HTML, <!-- -->. , :

<!-- <!-- --> -->

:

<book title=BLR<!-- -->/>

:

<book <!-- -->/>

XML- , XML: <, >, &.

<description>

<,>,&

</description>

() , & ;.

:

&lt; <;

&gt; >;

&amp; &;

&apos; ;

&quot; .

, :

<description>





:


: 2016-04-03; !; : 578 |


:

:

, , .
==> ...

1875 - | 1507 -


© 2015-2024 lektsii.org - -

: 0.043 .