Java: Classes in Java Applications. 11. Using the Java Application Programming Interface public Member( String fName, St
Previous chapters include a number of examples of classes (or partial classes) from the themed application, the main pur
Kompajlirani Java kôd može se izvršavati na svakoj platformi. (hardver +
operacijski sustav) ... omogućuju, između ostalog, jednostavno mrežno
programiranje.
CSCE 515: Computer Network. Programming. ------ Java Network Programming
reference: Dave Hollinger. Wenyuan Xu. Department of Computer Science and.
Techniques of Java Programming: Sockets in Java. Manuel Oriol. May 10, 2006.
1 Introduction. Sockets are probably one of the features that is most used in ...
259. C H A P T E R 10. Concurrency. THREADS allow multiple activities to
proceed concurrently. Concurrent pro- gramming is harder than single-threaded
...
rent queues, a wait-free algorithm implemented using atomic compare- and-swap ..... it does so at the price of requiring primitive types to be wrapped when used as ... inflating it, avoiding the need for a dedicated spoiled bit in the lock data. ....
About the Course: Reading. Data Structures and Algorithm Analysis in Java,. 2nd
Edition by Mark Allen Weiss. ISBN-10: 0321370139 ...
through the electronic version of your Java book, I'm finding that you've retained
the same high level of ... rehash of the API nor treats the programmer like a
dummy. ... Not to mention downloadable for free! ... First I stumbled upon the
Threads in Java. • JVM allows to create multiple Java threads. – note: standard
JVM may run only a single Java process, but any number of threads.
number of threads that can access some resource. The basic idea of selected
method. Java Semaphore keeps count of permits to access mutual resources.
for All Things Concurrency for that, see Concurrent Programming in Java (Lea,
2000). Rather, it offers ..... The AWT (Abstract Window Toolkit) and Swing.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson
Education, Inc. All rights reserved. 1. Chapter 6 Arrays ...
The applet code is embedded into HTML file using the tag. Attributes of ..... current value of the scroll bar one unit in the direction of the arrow.
Threads in Java. A thread is a call sequence that executes independently of
others, while at the same time possibly sharing system resources. First, we show
...
PLAYING AN AUDIO CLIP USING A MORE SOPHISTICATED APPROACH. .....
the JVM will call the corresponding update method for that object. ..... J. Lam, “
Java and Java Tools: Waking Up the Web,” PC Magazine, June 11, 1996. [2].
OOP: Collections. 3. Array, Example. • Helper class java.util. ... minimal dummy
class. Car[] cars1;. // null reference ... the same interface. [Source: java.sun.com] ...
Synchronization in Java. We often want threads to co-operate, typically in how
they access shared data structures. Since thread execution is asynchronous, the
...
Java. Libraries. Native libraries. (C, Fortranâ¦) Exec. OSR. JNI. FastR. Runtime. R interpreter written in. Java. 47 KL
The core package java.net contains a number of classes that allow programmers
to carry out network programming. – ContentHandler. – DatagramPacket.
on transnational activism, one Blora forest campaigner noted that activists from outside. Indonesia ... trust than phone meetings or email exchanges. ...... under one event banner, systematically planning, developing and marketing culture (Getz.
Data Structures in. Java. Session 23. Instructor: Bert Huang http://www.cs.
columbia.edu/~bert/courses/3134. Page 2. Announcements. • Homework 6 due
Dec.
Threads in Java. To put code in a thread, extend the built-in Thread class and
override run: class HelloThread extends Thread { public void run() {.
Based on Java Network Programming and Distributed Computing Netprog 2002 TCP/IP 1
UDP Advantages
• Less overhead (no connection establishment) • More efficient (no guaranteed delivery) • Real-time applications (no error checking or flow-control)
• E.g., weather, time, video, audio, games
• Data reception from more than one machine Netprog 2002 TCP/IP
2
Internet Addresses
•java.net.InetAddress class • You get an address by using static methods: ad = InetAddress.getByName(hostname); myAddress = InetAddress.getLocalHost();
Netprog 2002 TCP/IP 3
Printing Internet Addresses
• You get information from an InetAddress by using methods: ad.getHostName(); ad.getHostAddress();
• Example. Netprog 2002 TCP/IP 4
UDP Sockets Programming
• Sending/Receiving data.
•java.net.DatagramPacket class
• Creating UDP sockets.
• Client • Server •java.net.DatagramSocket class Netprog 2002 TCP/IP 5
Creating a UDP packet // to receive data from a remote machine DatagramPacket packet = new DatagramPacket(new byte[256], 256); // to send data to a remote machine DatagramPacket packet = new DatagramPacket( new byte[128], 128, address, port );
Netprog 2002 TCP/IP 6
Creating UDP sockets
• A UDP socket can be used both for reading and writing packets.
• Write operations are asynchronous; however, read operations are blocking.
• Since there is no guaranteed delivery, a single-threaded application could stall. Netprog 2002 TCP/IP 7
Creating UDP Sockets // A client datagram socket: DatagramSocket clientSocket = new DatagramSocket(); // A server datagram socket: DatagramSocket serverSocket = new DatagramSocket(port);
Netprog 2002 TCP/IP 8
Listening for UDP Packets // create datagram packet . . . // create datagram server socket . . . boolean finished = false; while ( ! finished ) { serverSocket.receive (packet); // process the packet } serverSocket.close(); Netprog 2002 TCP/IP 9
Processing UDP Packets ByteArrayInputStream bin = new ByteArrayInputStream( packet.getData() ); DataInputStream din = new DataInputStream(bin); // read the contents of the packet
Netprog 2002 TCP/IP 10
Sending UDP Packets // create datagram packet . . . // create datagram client socket . . . boolean finished = false; while ( ! finished ) { // write data to packet buffer clientSocket.send (packet); // see if there is more to send } Netprog 2002 TCP/IP 11
Sending UDP packets
• When you receive a packet, the ip and port number of the sender are set in the DatagramPacket.
• You can use the same packet to reply, by overwriting the data, using the method:
(with a given hostname and service port number) Create UDP packet. Call send(packet), sending request to the server. Possibly call receive(packet) (if we need a reply). Netprog 2002 TCP/IP 14
Typical UDP Server code
• Create UDP socket listening to a well • • •
known port number. Create UDP packet buffer Call receive(packet) to get a request, noting the address of the client. Process request and send reply back with send(packet). Netprog 2002 TCP/IP 15
Debugging
• Debugging UDP can be difficult. • Write routines to print out addresses. • Use a debugger. • Include code that can handle unexpected situations.
Netprog 2002 TCP/IP 16
Asynchronous Errors
• What happens if a client sends data to a server that is not running?
• ICMP • •
“port unreachable” error is generated by receiving host and send to sending host. The ICMP error may reach the sending host after send() has already returned! The next call dealing with the socket could return the error. Netprog 2002 TCP/IP 17