Sockets. Programação de Sockets em Java. Socket Abstractions. Camada de Transporte

Size: px
Start display at page:

Download "Sockets. Programação de Sockets em Java. Socket Abstractions. Camada de Transporte"

Transcription

1 Sockets Programação de Sockets em Java Server ports lients user space TP/UDP Socket API TP/UDP kernel space IP IP Ethernet Adapter Ethernet Adapter hardware SISTEMAS INFORMÁTIOS I, ENG. BIOMÉDIA SLIDES_10 Socket Abstractions amada de Transporte File server Mail server WWW server UDP: User Datagram Protocol - no acknowledgements - no retransmissions - out of order, duplicates possible - connectionless TP: Transmission ontrol Protocol - reliable (in order, all arrive, no duplicates) - flow control - connection 1

2 Package java.net The java.net package provides networking support in java. InetAddress The java.net.inetaddress class represents an IP address. lasses DatagramPacket DatagramSocket InetAddress ServerSocket Socket Exceptions BindException onnectexception MalformedURLException NoRouteToHostException ProtocolException SocketException UnknownHostException UnknownServiceException - public byte[] getaddress(); - public static InetAddress[] getallbyname(string host); - public static InetAddress getbyname(string host); - public String gethostname(); - public static InetAddress getlocalhost(); Exemplo: InetAddress import java.io.* ; import java.net.* ; public class InetAddressTest { public static void main( String args[] ) { try { InetAddress myself = InetAddress.getLocalHost(); InetAddress machine = InetAddress.getByName(" System.out.println("My name : " + myself.gethostname()); System.out.println("My IP : " + myself.gethostaddress()); System.out.println("UnivSite name : " + machine.gethostname()); System.out.println("UnivSite IP : " + machine.gethostaddress()); catch (UnknownHostException e) { System.out.println ("ould not find address "); catch (IOException e) { System.out.println (e); Ports Port numbers can be: Well-known (port ) Dynamic or private (port ) Servers/daemons usually use well-known ports Any client can identify the server/service HTTP = 80, FTP = 21, Telnet = 23,... lients usually use dynamic ports Assigned by the kernel at run time A full address for a socket is then: IP address + port number ex: student.dei.uc.pt: : 9090 NTP daemon TP/UDP IP Web server port 123 port 80 Ethernet Adapter 2

3 Sockets Stream Stream Sockets (TP) class Socket onnects to a ServerSocket. class ServerSocket Accepts requests for socket connections. reates a new Socket for each connection. TP service: reliable transfer of bytes from one process to another riação de Sockets Server and Ports Each Socket object is associated with exactly one remote host. To connect to a different host, you must create a new Socket object. You specify the remote host and the port to connect. The host may be specified as a string like eden.dei.uc.pt" or an InetAddress object. The port should be an int between 1 and Socket s = new Socket( On Unix systems (but not Windows) your program must be running as root to bind to a port between 1 and is a special port number. It tells the system to pick on of the available ports. Many well known ports echo 7 time 13 ftp 21 telnet 23 finger 79 smpt 25 http 80 3

4 lients and Ports lient/server socket interaction: TP The client is assigned a port number on the local machine as part of establishing the connection. How to know the number of the local port: getlocalport() A client can connect to a particular port by using programs such as telnet, as follows: telnet 80 hostid create socket, port=x, for incoming request: welcomesocket = ServerSocket() wait for incoming connection request connectionsocket = welcomesocket.accept() read request from connectionsocket write reply to connectionsocket close connectionsocket create socket, connect to hostid, port=x clientsocket = Socket() send request using clientsocket read reply from clientsocket close clientsocket Socket Socket(InetAddress address, int port) reates a stream socket and connects it to the specified port number at the specified IP address. InputStream getinputstream() Returns an input stream for this socket. OutputStream getoutputstream() Returns an output stream for this socket. void close() closes this socket (cuts the connection) ServerSocket A server socket that can wait for connections from other machines public ServerSocket(int port) throws IOException reates a ServerSocket that will receive connection requests on the specified port. public Socket accept() throws IOException Waits for an incoming connection request, creates the connection, and returns the Socket created on this end. public void close() throws IOException closes the socket connection. 4

5 ServerSockets A ServerSocket binds to a particular local port. Then it calls accept() to listen for incoming connections; accept() blocks until a connection is detected. When accept() unblocks this means that a client has connected. It returns a Socket object which is used to communicate with the remote client. There are no getinputstream() or getoutputstream() methods for ServerSocket. Server ServerSocket(1234) Output/write stream lient Input/read stream Socket( , 1234) Exemplo: ServerSocket 1. class ServerExample { 2. public static void main(string[] args) { 3. try { 4. ServerSocket ssock = new ServerSocket(3333); 5. Socket sock = ssock.accept(); 6. BufferedReader br = new BufferedReader( 7. new InputStreamReader(sock.getInputStream())); 8. System.out.println(br.readLine()); 9. sock.close(); 10. catch(exception e) { Exemplo: client Socket class lientexample { public static void main(string[] args) { try { Socket sock = new Socket( server.dei.uc.pt, 3333); PrintWriter out = new PrintWriter( sock.getoutputstream(), true); out.println( Hello ); sock.close(); catch(exception e) {... 5

6 BufferedReader methods void close() lose the stream. int read() Read a single character. int read(char[] cbuf, int off, int len) Read characters into a portion of an array. String readline() Read a line of text. DataInputStream methods int read(byte[] b) reads some number of bytes into the buffer array b. int read(byte[] b, int off, int len) reads up to len bytes into an array of bytes. char readhar() reads a char. double readdouble() reads a double value. int readint() reads a int value. void readfully(byte[] b) reads some bytes and stores them into the buffer array. String readline() Deprecated. This method does not properly convert bytes to characters. The preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form: DataInputStream d = new DataInputStream(in); with: BufferedReader d = new BufferedReader(new InputStreamReader(in)); String readutf() reads a string (encoded in UTF-8 format). DataOutputStream methods PrintWriter methods void flush() flushes this data output stream. void write(int b) writes the specified byte. void writedouble(double v) writes a double. void writeint(int v) writes an int. void writeutf(string str) Writes a string. void close() lose the stream. void flush() Flush the stream. void print(char c) Print a character. void print(char[] s) Print an array of chars. void print(double d) Print a double. void print(int i) Print an integer. void print(object obj) Print an object. void print(string s) Print a string. void write(char[] buf) Write an array of chars. 6

7 Exceptions Exceptions exceptions: Almost all methods in networking classes throw IOExceptions that must be caught because of potential network problems. try { Socket client = new Socket(host, port); handleonnection(client); catch(unknownhostexception uhe) { System.out.println("Unknown host: " + host); uhe.printstacktrace(); catch(ioexception ioe) { System.out.println("IOException: " + ioe); ioe.printstacktrace(); liente Outro Exemplo: Sockets TP // 1. reate a Socket Object: client = new Socket( server, port_id ); // 2. reate I/O streams for communicating with the server. is = new DataInputStream(client.getInputStream() ); os = new DataOutputStream( client.getoutputstream() ); // 3. Perform I/O or communication with the server: // Receive data from the server: String line = is.readline(); // Send data to the server: os.writebytes("hello\n"); // 4. lose the socket when done: client.close(); 7

8 Server // 1- Open the Server Socket: ServerSocket server; DataOutputStream os; DataInputStream is; server = new ServerSocket( PORT ); // 2- Wait for the lient Request: Socket client = server.accept(); // 3- reate I/O streams for communicating to the client is = new DataInputStream( client.getinputstream() ); os = new DataOutputStream( client.getoutputstream() ); // 4- Perform communication with client // Receive from client: String line = is.readline(); // Send to client: os.writebytes("hello\n"); // 5- lose sockets: client.close(); For multithreaded server: while(true) { i. wait for client requests (step 2 above) ii. create a thread with client socket as parameter (the thread creates streams (as in step (3) and does communication as stated in (4). Remove thread once service is provided. Simple Server import java.io.*; public class SimpleServer{ public static void main(string args[]) throws IOException { // Register service on port 1234 ServerSocket s = new ServerSocket(1234); while(true){ Socket s1=s.accept(); // Wait and accept a connection // Get a stream associated with the socket OutputStream s1out = s1.getoutputstream(); DataOutputStream dos = new DataOutputStream (s1out); // Send a string! dos.writeutf("ola Boa Noite"); System.out.println("Respondeu ao cliente"); // lose the connection, but not the server socket dos.close(); s1out.close(); s1.close(); Try this example... Simple lient // Simplelient.java: a simple client program import java.net.*; import java.io.*; public class Simplelient { public static void main(string args[]) throws IOException { // Open your connection to a server, at port 1234 Socket s1 = new Socket( localhost",1234); // Get an input file handle from the socket and read the input InputStream s1in = s1.getinputstream(); DataInputStream dis = new DataInputStream(s1In); String st = new String (dis.readutf()); System.out.println(st); // When done, just close the connection and exit dis.close(); s1in.close(); s1.close(); Try this example... Run SimpleServer, Simplelient Run Server on localhost: java SimpleServer Run lient: java Simplelient Ola, Boa Noite If you run client when server is not up: sockets [1:147] java Simplelient Exception in thread "main" java.net.onnectexception: onnection refused at java.net.plainsocketimpl.socketonnect(native Method) at java.net.plainsocketimpl.doonnect(plainsocketimpl.java:320) at java.net.plainsocketimpl.connecttoaddress(plainsocketimpl.java:133) at java.net.plainsocketimpl.connect(plainsocketimpl.java:120) at java.net.socket.<init>(socket.java:273) at java.net.socket.<init>(socket.java:100) at Simplelient.main(Simplelient.java:6) 8

9 Binding When a ServerSocket object is created, it attempts to bind to the port on the local host given by the port argument. If another server socket is already listening to the port, there will be ajava.net.bindexception. No more than one process or thread can listen to a particular port at a time. For example, if there's already an HTTP server running on port 80, you won't be able to bind to port 80. Multiple lients Multiple clients can connect to the same port on the server at the same time. The server creates a separate socket for each client. Multithreaded Server Multi-Threaded Servers If a server needs to handle many connections at once, server programs should be multi-threaded. lient 1 Process Server Process TP/IP Server Threads lient 2 Process 9

10 Multi-threaded Server Multi-threaded Server (I) One ServerSocket can accept multiple clients simultaneously Use multithreading to handle them One thread waits for accept() Open a new thread for each connection. Rather than handling the connection directly the socket should be passed to a Thread object that handles the connection. ServerSocket server = new ServerSocket(PORT); // Server main loop while (true) { try { Socket clientsocket = server.accept(); lientthread thelient = new lientthread(clientsocket); thelient.start(); catch (Exception e) { // Error accepting one of the clients e.printstacktrace(); Multi-threaded Server (II) class lientthread extends Thread { private Socket clientsocket; public lientthread(socket clientsocket) { this.clientsocket = clientsocket; Threading a Server Threads handles the communication between one client and the server, by spawning a new thread every time a new client connects. This is often accomplished in /++ on a Unix OS by using fork. Nowadays the use of Pthreads is also common. In Java it is simpler thanks to the use of Java Threads. public void run() { // Handle the client request here! 10

11 TDayTimeServer.java onnection.java import java.net.*; import java.io.*; import java.util.*; public class TDayTimeServer { public static void main(string argv[]) { try { ServerSocket listen = new ServerSocket(0); System.out.println("Listening on:"+listen.getlocalport()); for(;;) { Socket client = listen.accept(); System.out.println(clnt.toString()); onnection c = new onnection(client); catch(exception e) { System.out.println("Server terminated"); import java.net.*; import java.io.*; import java.util.*; class onnection extends Thread { protected Socket clnt; public onnection(socket sock) { clnt = sock; this.start(); public void run() { Date today = new Date(); try { PrintWriter out = new PrintWriter(clnt.getOutputStream(), true); out.println(today); client.close(); catch (IOException e) { Exemplos_Sockets.zip UDP Datagrams -TPlient.java -TPServer1.java -TPServer2.java (multithreaded server) 11

12 UDP - Java lasses DatagramSocket DatagramPacket represents a datagram packet DatagramSocket represents a socket for sending and receiving datagram packets MulticastSocket for sending and receiving IP multicast packets // onstructors DatagramSocket() onstructs a datagram socket and binds it to any available port on the local host machine. DatagramSocket(int port) onstructs a datagram socket and binds it to the specified port on the local host machine. DatagramSocket(int port, InetAddress iaddr) // Methods void close() InetAddress getlocaladdress() int getlocalport() int getsotimeout() void receive(datagrampacket p) void send(datagrampacket p) setsotimeout(int timeout) lient/server socket interaction: UDP DatagramPacket hostid create socket, port=x, for incoming request: S_Socket = DatagramSocket() read request from S_Socket write reply to S_Socket specifying client host address, port number create socket, _Socket = DatagramSocket() reate, address (hostid, port=x, send datagram request using _Socket read reply from _Socket close _Socket //onstructors public DatagramPacket(byte[] buf, int length) onstructs a DatagramPacket for receiving. public DatagramPacket(byte[] buf, int length, InetAddress address, int port) onstructs a datagram for sending to the specified port number on the specified host. // Methods public synchronized InetAddress getaddress(); public synchronized int getport(); public synchornized byte[] getdata(); int getlength(); void setaddress(inetaddress iaddr); void setport(int iport); void setdata(byte ibuf[]); void setlength(int ilength); 12

13 DatagramPacket Datagram packet data is stored as a byte array: byte[]. To send a String message via a datagram we need to convert it to byte[]. The String class provides this via the getbytes() method. String msg = Olá ; byte[] buf = msg.getbytes(); Sending UDP Datagrams To send data to a particular server onvert the data into byte array. Pass this byte array, its length, the InetAddress and the destination port to the DatagramPacket() constructor. Next create a DatagramSocket and send the packet by using the send() method. Sending a DatagramPacket DatagramSocket try { InetAddress addr = InetAddress.getByName( eden.dei.uc.pt"); int port = 9000; String msg = Olá Boa Noite"; byte[] msgbytes = msg.getbytes(); DatagramPacket packet = new DatagramPacket(msgBytes, msgbytes.length, addr, port); DatagramSocket sender = new DatagramSocket(); sender.send(packet); catch (Exception e) { System.err.println(e); public void send(datagrampacket p) throws IOException Sends a datagram packet from this socket. The DatagramPacket includes information indicating the data to be sent, its length, the IP address of the remote host, and the port number on the remote host. 13

14 DatagramSocket public void receive(datagrampacket p) throws IOException Receives a datagram packet from this socket. When this method returns, the DatagramPacket's buffer is filled with the data received. The datagram packet also contains the sender's IP address, and the port number on the sender's machine. It blocks until a datagram packet is received. If the message is longer than byte[] the message will be truncated UDP + TP Ports There are separated ports for UDP and TP. Each computer has 65,536 UDP ports as well as its 65,536 TP ports. A server socket can be bound to TP port 20 at the same time as a datagram socket is bound to UDP port 20. DatagramSocket (client) DatagramSocket socket = new DatagramSocket(); // send request InetAddress address = InetAddress.getByName( eden.dei.uc.pt ); String s = get_current_time_date ; byte [] b = s.getbytes(); DatagramPacket packet = new DatagramPacket(b, b.length, address, 4445); socket.send(packet); // get response byte[] buf = new byte[256]; packet = new DatagramPacket(buf, buf.length); socket.receive(packet); // display response String received = new String(packet.getData()); System.out.println( the time: + received); socket.close(); DatagramSocket (server) DatagramSocket socket = new DatagramSocket(); // receives a packet request byte[] buf = new byte[256]; DatagramPacket packetrequest = new DatagramPacket(buf, buf.length); socket.receive(packetrequest); // Display the request byte[] data = packetrequest.getdata(); String s = new String(data, 0, data.getlength()); System.out.println("Port " + packet1.getport() + " on " + packet1.getaddress() + " sent this message: + s); if (s.equals( get_current_time_date )) { String thedate = (new Date()).toString(); byte[] bufsend = thedate.getbytes(); InetAddress address = packetrequest.getaddress(); int port = packetrequest.getport(); DatagramPacket responsepacket = new DatagramPacket(bufSend,bufSend.length,address,port); socket.send(responsepacket); 14

15 Datagrams Received... Use getport() and getaddress() to tell where the packet come from, getdata() to retrieve the data, and getlength() to see how many bytes were in the data. If the received packet was too long for the buffer, it's truncated to the length of the buffer. Length is reset when packet is received. Exemplos_Sockets.zip -UDPlient.java -UDPServer.java Uso de Recursos: TP vs UDP N clientes simultâneos N sockets no Servidor TP SERVER ServerSocket Leitura de Mensagens Grandes em Sockets Stream Socket Socket Socket Socket Socket Socket UDP SERVER Socket int size,tam=0; while(tam < N){ size=in.readbytes(...); tam = tam + size; N clientes simultâneos 1 socket no Servidor 15

16 Objectos Programamos objectos complexos. Object Serialization Queremos guardar o estado dos objectos em disco.. Queremos enviar objectos para outros processos através de um socket... Object Serialization Object Serialization Suppose that you have an object and want to send it across a socket ( ) Pessoa p = new Pessoa( Bush, 50); // enviar o objecto p através de um socket ( ) public class Pessoa{ private String name; private int age; public Pessoa(String name, int age) { this.name = name; this.age = age; public String tostring() { return "[" + name + "/" + age + "]"; Object Serialization It is possible to send complete objects through a socket stream ObjectInputStream.readObject() ObjectOutputStream.writeObject() When reading an object from a ObjectInputStream, it is necessary to cast it to the appropriate type Pessoa p = (Pessoa) in.readobject(); For being able to send object through a stream, they must be serializable (i.e. they must implement java.io.serializable) Although many classes are serializable, some are not Ex: a Thread is not serializable 16

17 Guardar Objectos em Disco 1. Mark your class serializable public class MylassA implements Serializable {... // in some other code elsewhere... MylassA tmp=new MylassA(arg); FileOutputStream fos=new FileOutputStream( some.obj ); ObjectOutputStream out=new ObjectOutputStream(fos); out.writeobject(tmp); out.flush(); out.close(); public class Pessoa implements java.io.serializable { private String name; private int age; public Pessoa(String name, int age) { this.name = name; this.age = age; public String tostring() { return "[" + name + "/" + age + "]"; 2. Use the ObjectStreams Reading ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream()); Pessoa x = (Pessoa) in.readobject(); System.out.println(x); Writing ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); Pessoa p = new Pessoa( Busha, 50); out.writeobject(p); Examplo Serialização Objectos class Data implements Serializable { private int i; private int tabela[]; public Data(int x){ i = x; tabela = new int[10]; for(int j=0;j<10;j++) tabela[j]=x; public String tostring() { return Integer.toString(i); public void print_conteudo() { for(int j=0;j<10;j++) System.out.print(tabela[j]+" " ); System.out.println(); 17

18 lient: TPlient_O public class TPlient_O { public static void main (String args[]) { String texto; Socket s = null; int serversocket = 6000; try{ // 1o passo s = new Socket(host, serversocket); // // 2o passo DataInputStream in = new DataInputStream( s.getinputstream()); DataOutputStream out = new DataOutputStream( s.getoutputstream()); // riar ObjecOutputStream e ObjectInputStream ObjectOutputStream obj_o = new ObjectOutputStream(out); ObjectInputStream obj_i = new ObjectInputStream(in); int contador=0; // 3o passo while(contador < 5){ contador++; Data d = new Data(contador); obj_o.writeobject(d); obj_o.flush(); d.print_conteudo(); System.out.println("ENVIEI OBJETO"); String data = in.readutf(); System.out.println("Received: "+ data); Server: TPServer1_O public class TPServer1_O{ public static void main(string args[]) throws IOException,lassNotFoundException{ int serverport = 6000; // listensocket = new ServerSocket(serverPort); while(true){ System.out.println("A esperade ligacaono socket "+serverport); try{ clientsocket = listensocket.accept(); in = new DataInputStream(clientSocket.getInputStream()); out = new DataOutputStream(clientSocket.getOutputStream()); // riar ObjectinputStream e ObjectOutputStream ObjectOutputStream obj_o = new ObjectOutputStream(out); ObjectInputStream obj_i = new ObjectInputStream(in); Data d; while(true){ d = (Data)obj_i.readObject(); System.out.println("Recebeu: "+d); d.print_conteudo(); out.writeutf("objeto OK"); out.flush(); // while //... catches. //... catches... Overwriting writeobject/readobject Exemplos_Sockets.zip -TPlient_O.java -TPServer1_O.java public class Demolass implements Serializable { private int _dat=3; private static int _sdat=2; private void writeobject(objectoutputstream o) throws IOException { o.writeint(_dat); o.writeint(_sdat); private void readobject(objectinputstream i) throws IOException, lassnotfoundexception { _dat=i.readint(); _sdat=i.readint(); 18

19 Objecto com partes não-serializáveis What happens if class Foo has a field of type Bar, but Bar isn t serializable? Foo tmp=new Foo(); ObjectOutputStream out=new ObjectOutputStream; out.writeobject(tmp); You get a NotSerializableException Answer: use read/writeobject to explicitly serialize parts that can t be handled otherwise 19

NETWORK PROGRAMMING IN JAVA USING SOCKETS

NETWORK PROGRAMMING IN JAVA USING SOCKETS NETWORK PROGRAMMING IN JAVA USING SOCKETS Prerna Malik, Poonam Rawat Student, Dronacharya College of Engineering, Gurgaon, India Abstract- Network programming refers to writing programs that could be processed

More information

Network/Socket Programming in Java. Rajkumar Buyya

Network/Socket Programming in Java. Rajkumar Buyya Network/Socket Programming in Java Rajkumar Buyya Elements of C-S Computing a client, a server, and network Client Request Result Network Server Client machine Server machine java.net Used to manage: URL

More information

Agenda. Network Programming and Java Sockets. Introduction. Internet Applications Serving Local and Remote Users

Agenda. Network Programming and Java Sockets. Introduction. Internet Applications Serving Local and Remote Users Programming and Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering University of Melbourne, Australia http://www.cs.mu.oz.au/~raj

More information

Java Network. Slides prepared by : Farzana Rahman

Java Network. Slides prepared by : Farzana Rahman Java Network Programming 1 Important Java Packages java.net java.io java.rmi java.security java.lang TCP/IP networking I/O streams & utilities Remote Method Invocation Security policies Threading classes

More information

Socket Programming in Java

Socket Programming in Java Socket Programming in Java Learning Objectives The InetAddress Class Using sockets TCP sockets Datagram Sockets Classes in java.net The core package java.net contains a number of classes that allow programmers

More information

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets Transport layer protocols Interprocess communication Synchronous and asynchronous comm. Message destination Reliability Ordering Client Server Lecture 15: Operating Systems and Networks Behzad Bordbar

More information

Network Communication

Network Communication Network Communication Outline Sockets Datagrams TCP/IP Client-Server model OSI Model Sockets Endpoint for bidirectional communication between two machines. To connect with each other, each of the client

More information

Socket Programming. A er learning the contents of this chapter, the reader will be able to:

Socket Programming. A er learning the contents of this chapter, the reader will be able to: Java Socket Programming This chapter presents key concepts of intercommunication between programs running on different computers in the network. It introduces elements of network programming and concepts

More information

The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets

The difference between TCP/IP, UDP/IP and Multicast sockets. How servers and clients communicate over sockets Network Programming Topics in this section include: What a socket is What you can do with a socket The difference between TCP/IP, UDP/IP and Multicast sockets How servers and clients communicate over sockets

More information

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP

Learning Outcomes. Networking. Sockets. TCP/IP Networks. Hostnames and DNS TCP/IP CP4044 Lecture 7 1 Networking Learning Outcomes To understand basic network terminology To be able to communicate using Telnet To be aware of some common network services To be able to implement client

More information

Network Programming using sockets

Network Programming using sockets Network Programming using sockets TCP/IP layers Layers Message Application Transport Internet Network interface Messages (UDP) or Streams (TCP) UDP or TCP packets IP datagrams Network-specific frames Underlying

More information

Creating a Simple, Multithreaded Chat System with Java

Creating a Simple, Multithreaded Chat System with Java Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate

More information

Java Programming: Sockets in Java

Java Programming: Sockets in Java Java Programming: Sockets in Java Manuel Oriol May 10, 2007 1 Introduction Network programming is probably one of the features that is most used in the current world. As soon as people want to send or

More information

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime?

Question1-part2 What undesirable consequences might there be in having too long a DNS cache entry lifetime? CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Working as a group. Working in small gruops of 2-4 students. When you work as a group, you have to return only one home assignment per

More information

Data Communication & Networks G22.2262-001

Data Communication & Networks G22.2262-001 Data Communication & Networks G22.2262-001 Session 10 - Main Theme Java Sockets Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences 1 Agenda

More information

Division of Informatics, University of Edinburgh

Division of Informatics, University of Edinburgh CS1Bh Lecture Note 20 Client/server computing A modern computing environment consists of not just one computer, but several. When designing such an arrangement of computers it might at first seem that

More information

Corso di Reti di Calcolatori

Corso di Reti di Calcolatori Corso di Reti di Calcolatori UNICAL Facoltà di Ingegneria a.a. 2002/2003 Esercitazione sul networking in Java (1 a parte) paolo.trunfio@deis.unical.it 1 java.net.inetaddress static InetAddress getbyname(string

More information

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Application Development with TCP/IP. Brian S. Mitchell Drexel University Application Development with TCP/IP Brian S. Mitchell Drexel University Agenda TCP/IP Application Development Environment Client/Server Computing with TCP/IP Sockets Port Numbers The TCP/IP Application

More information

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol).

Java Network Programming. The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol). Java Network Programming The java.net package contains the Socket class. This class speaks TCP (connection-oriented protocol). The DatagramSocket class uses UDP (connectionless protocol). The java.net.socket

More information

Assignment 4 Solutions

Assignment 4 Solutions CSCI 312 - DATA COMMUNICATIONS AND NETWORKS FALL, 2014 Assignment 4 Solutions Working as a pair Working in pairs. When you work as a pair you have to return only one home assignment per pair on a round.

More information

Corso di Reti di Calcolatori. java.net.inetaddress

Corso di Reti di Calcolatori. java.net.inetaddress Corso di Reti di Calcolatori UNICAL Facoltà di Ingegneria a.a. 2002/2003 Esercitazione sul networking in Java (1 a parte) paolo.trunfio@deis.unical.it 1 java.net.inetaddress static InetAddress getbyname(string

More information

CS 1302 Ch 19, Binary I/O

CS 1302 Ch 19, Binary I/O CS 1302 Ch 19, Binary I/O Sections Pages Review Questions Programming Exercises 19.1-19.4.1, 19.6-19.6 710-715, 724-729 Liang s Site any Sections 19.1 Introduction 1. An important part of programming is

More information

SSC - Communication and Networking Java Socket Programming (II)

SSC - Communication and Networking Java Socket Programming (II) SSC - Communication and Networking Java Socket Programming (II) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics Multicast in Java User Datagram

More information

INPUT AND OUTPUT STREAMS

INPUT AND OUTPUT STREAMS INPUT AND OUTPUT The Java Platform supports different kinds of information sources and information sinks. A program may get data from an information source which may be a file on disk, a network connection,

More information

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM Socket Programming Rohan Murty Hitesh Ballani Last Modified: 2/8/2004 8:30:45 AM Slides adapted from Prof. Matthews slides from 2003SP Socket programming Goal: learn how to build client/server application

More information

Principles, Models, and Applications for Distributed Systems M

Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M C/S applications using Java Sockets Luca Foschini SOCKET for COMMUNICATION Need for

More information

Socket-based Network Communication in J2SE and J2ME

Socket-based Network Communication in J2SE and J2ME Socket-based Network Communication in J2SE and J2ME 1 C/C++ BSD Sockets in POSIX POSIX functions allow to access network connection in the same way as regular files: There are special functions for opening

More information

CISC 4700 L01 Network & Client- Server Programming Spring 2016. Harold, Chapter 8: Sockets for Clients

CISC 4700 L01 Network & Client- Server Programming Spring 2016. Harold, Chapter 8: Sockets for Clients CISC 4700 L01 Network & Client- Server Programming Spring 2016 Harold, Chapter 8: Sockets for Clients Datagram: Internet data packet Header: accounting info (e.g., address, port of source and dest) Payload:

More information

Lesson: All About Sockets

Lesson: All About Sockets All About Sockets http://java.sun.com/docs/books/tutorial/networking/sockets/index.html Page 1 sur 1 The Java TM Tutorial Start of Tutorial > Start of Trail Trail: Custom Networking Lesson: All About Sockets

More information

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files

File I/O - Chapter 10. Many Stream Classes. Text Files vs Binary Files File I/O - Chapter 10 A Java stream is a sequence of bytes. An InputStream can read from a file the console (System.in) a network socket an array of bytes in memory a StringBuffer a pipe, which is an OutputStream

More information

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket.

String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivepacket.getaddress(); int port = receivepacket. 164 CHAPTER 2 APPLICATION LAYER connection requests, as done in TCPServer.java. If multiple clients access this application, they will all send their packets into this single door, serversocket. String

More information

Building a Multi-Threaded Web Server

Building a Multi-Threaded Web Server Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous

More information

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers

DNS: Domain Names. DNS: Domain Name System. DNS: Root name servers. DNS name servers DNS: Domain Name System DNS: Domain Names People: many identifiers: SSN, name, Passport # Internet hosts, routers: Always: IP address (32 bit) - used for addressing datagrams Often: name, e.g., nifc14.wsu.edu

More information

Socket Programming. Announcement. Lectures moved to

Socket Programming. Announcement. Lectures moved to Announcement Lectures moved to 150 GSPP, public policy building, right opposite Cory Hall on Hearst. Effective Jan 31 i.e. next Tuesday Socket Programming Nikhil Shetty GSI, EECS122 Spring 2006 1 Outline

More information

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1 Introduction to Java Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233 ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1 What Is a Socket? A socket is one end-point of a two-way

More information

JAVA Program For Processing SMS Messages

JAVA Program For Processing SMS Messages JAVA Program For Processing SMS Messages Krishna Akkulu The paper describes the Java program implemented for the MultiModem GPRS wireless modem. The MultiModem offers standards-based quad-band GSM/GPRS

More information

Simple Java I/O. Streams

Simple Java I/O. Streams Simple Java I/O Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for data (sometimes both) An input stream may be associated with the keyboard An

More information

TP1 : Correction. Rappels : Stream, Thread et Socket TCP

TP1 : Correction. Rappels : Stream, Thread et Socket TCP Université Paris 7 M1 II Protocoles réseaux TP1 : Correction Rappels : Stream, Thread et Socket TCP Tous les programmes seront écrits en Java. 1. (a) Ecrire une application qui lit des chaines au clavier

More information

Socket programming. Complement for the programming assignment INFO-0010

Socket programming. Complement for the programming assignment INFO-0010 Socket programming Complement for the programming assignment INFO-0010 Outline Socket definition Briefing on the Socket API A simple example in Java Multi-threading and Synchronization HTTP protocol Debugging

More information

Abstract Stream Socket Service

Abstract Stream Socket Service COM 362 Computer Networks I Lec 2: Applicatin Layer: TCP/UDP Socket Programming 1. Principles of Networks Applications 2. TCP Socket Programming 3. UDP Socket Programming Prof. Dr. Halûk Gümüşkaya haluk.gumuskaya@gediz.edu.tr

More information

! "# $%&'( ) * ).) "%&' 1* ( %&' ! "%&'2 (! ""$ 1! ""3($

! # $%&'( ) * ).) %&' 1* ( %&' ! %&'2 (! $ 1! 3($ ! "# $%&'( ) * +,'-( ).) /"0'" 1 %&' 1* ( %&' "%&'! "%&'2 (! ""$ 1! ""3($ 2 ', '%&' 2 , 3, 4( 4 %&'( 2(! ""$ -5%&'* -2%&'(* ) * %&' 2! ""$ -*! " 4 , - %&' 3( #5! " 5, '56! "* * 4(%&'(! ""$ 3(#! " 42/7'89.:&!

More information

Network-based Applications. Pavani Diwanji David Brown JavaSoft

Network-based Applications. Pavani Diwanji David Brown JavaSoft Network-based Applications Pavani Diwanji David Brown JavaSoft Networking in Java Introduction Datagrams, Multicast TCP: Socket, ServerSocket Issues, Gotchas URL, URLConnection Protocol Handlers Q & A

More information

Advanced Network Programming Lab using Java. Angelos Stavrou

Advanced Network Programming Lab using Java. Angelos Stavrou Advanced Network Programming Lab using Java Angelos Stavrou Table of Contents A simple Java Client...3 A simple Java Server...4 An advanced Java Client...5 An advanced Java Server...8 A Multi-threaded

More information

WRITING DATA TO A BINARY FILE

WRITING DATA TO A BINARY FILE WRITING DATA TO A BINARY FILE TEXT FILES VS. BINARY FILES Up to now, we have looked at how to write and read characters to and from a text file. Text files are files that contain sequences of characters.

More information

Slides for Chapter 4: Interprocess Communication

Slides for Chapter 4: Interprocess Communication Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, Addison-Wesley 2012 Text extensions to slides David E.

More information

An Android-based Instant Message Application

An Android-based Instant Message Application An Android-based Instant Message Application Qi Lai, Mao Zheng and Tom Gendreau Department of Computer Science University of Wisconsin - La Crosse La Crosse, WI 54601 mzheng@uwlax.edu Abstract One of the

More information

AVRO - SERIALIZATION

AVRO - SERIALIZATION http://www.tutorialspoint.com/avro/avro_serialization.htm AVRO - SERIALIZATION Copyright tutorialspoint.com What is Serialization? Serialization is the process of translating data structures or objects

More information

D06 PROGRAMMING with JAVA

D06 PROGRAMMING with JAVA Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch16 Files and Streams PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for

More information

Package java.net. Interfaces. Classes. Exceptions. Package java.net Page 1 of 1. All Packages

Package java.net. Interfaces. Classes. Exceptions. Package java.net Page 1 of 1. All Packages Package java.net Page 1 of 1 Package java.net All Packages Interfaces ContentHandlerFactory FileMap SocketImplFactory URLStreamHandlerFactory Classes ContentHandler DatagramPacket DatagramSocket DatagramSocketImpl

More information

Tutorial on Socket Programming

Tutorial on Socket Programming Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Seyed Hossein Mortazavi (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian, ) 1 Outline Client- server

More information

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)

The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits) Binary I/O streams (ascii, 8 bits) InputStream OutputStream The Java I/O System The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing Binary I/O to Character I/O

More information

A Tutorial on Socket Programming in Java

A Tutorial on Socket Programming in Java A Tutorial on Socket Programming in Java Natarajan Meghanathan Assistant Professor of Computer Science Jackson State University Jackson, MS 39217, USA Phone: 1-601-979-3661; Fax: 1-601-979-2478 E-mail:

More information

Rappels programma,on réseau Java- suite. C. Delporte M2- Internet Rappel Java 1

Rappels programma,on réseau Java- suite. C. Delporte M2- Internet Rappel Java 1 Rappels programma,on réseau Java- suite C. Delporte M2- Internet Rappel Java 1 Socket programming Two socket types for two transport services: UDP: unreliable datagram TCP: reliable, byte stream-oriented

More information

Preface. Intended Audience

Preface. Intended Audience Preface For years, college courses in computer networking were taught with little or no hands on experience. For various reasons, including some good ones, instructors approached the principles of computer

More information

Goal: learn how to build client/server application that communicate using sockets. An interface between application and network

Goal: learn how to build client/server application that communicate using sockets. An interface between application and network Socket programming Goal: learn how to build client/server application that communicate using sockets Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server

More information

When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer

When the transport layer tries to establish a connection with the server, it is blocked by the firewall. When this happens, the RMI transport layer Firewall Issues Firewalls are inevitably encountered by any networked enterprise application that has to operate beyond the sheltering confines of an Intranet Typically, firewalls block all network traffic,

More information

Today s Outline. Computer Communications. Java Communications uses Streams. Wrapping Streams. Stream Conventions 2/13/2016 CSE 132

Today s Outline. Computer Communications. Java Communications uses Streams. Wrapping Streams. Stream Conventions 2/13/2016 CSE 132 Today s Outline Computer Communications CSE 132 Communicating between PC and Arduino Java on PC (either Windows or Mac) Streams in Java An aside on class hierarchies Protocol Design Observability Computer

More information

Threads in der Client/Server-Programmierung mit Java

Threads in der Client/Server-Programmierung mit Java Threads in der Client/Server-Programmierung mit Java Zahlenraten: Protokoll CLIENT / Comm? Comm! / max / SERVER Comm? / Comm! / 100 trial / / cmp(trial) [ cmp(trial) = < or cmp(trial) = > ] [ answer =

More information

public static void main(string[] args) { System.out.println("hello, world"); } }

public static void main(string[] args) { System.out.println(hello, world); } } Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static

More information

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, 4802-4807. Socket Programming

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, 4802-4807. Socket Programming Socket Programming Limi Kalita M.Tech Student, Department of Computer Science and Engineering, Assam Down Town University, Guwahati, India. Abstract: The aim of the paper is to introduce sockets, its deployment

More information

What is an I/O Stream?

What is an I/O Stream? Java I/O Stream 1 Topics What is an I/O stream? Types of Streams Stream class hierarchy Control flow of an I/O operation using Streams Byte streams Character streams Buffered streams Standard I/O streams

More information

Mail User Agent Project

Mail User Agent Project Mail User Agent Project Tom Kelliher, CS 325 100 points, due May 4, 2011 Introduction (From Kurose & Ross, 4th ed.) In this project you will implement a mail user agent (MUA) that sends mail to other users.

More information

READING DATA FROM KEYBOARD USING DATAINPUTSTREAM, BUFFEREDREADER AND SCANNER

READING DATA FROM KEYBOARD USING DATAINPUTSTREAM, BUFFEREDREADER AND SCANNER READING DATA FROM KEYBOARD USING DATAINPUTSTREAM, BUFFEREDREADER AND SCANNER Reading text data from keyboard using DataInputStream As we have seen in introduction to streams, DataInputStream is a FilterInputStream

More information

Communicating with a Barco projector over network. Technical note

Communicating with a Barco projector over network. Technical note Communicating with a Barco projector over network Technical note MED20080612/00 12/06/2008 Barco nv Media & Entertainment Division Noordlaan 5, B-8520 Kuurne Phone: +32 56.36.89.70 Fax: +32 56.36.883.86

More information

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved.

Chapter 20 Streams and Binary Input/Output. Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved. Chapter 20 Streams and Binary Input/Output Big Java Early Objects by Cay Horstmann Copyright 2014 by John Wiley & Sons. All rights reserved. 20.1 Readers, Writers, and Streams Two ways to store data: Text

More information

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software Session NM059 TCP/IP Programming on VMS Geoff Bryant Process Software Course Roadmap Slide 160 NM055 (11:00-12:00) Important Terms and Concepts TCP/IP and Client/Server Model Sockets and TLI Client/Server

More information

Building a Java chat server

Building a Java chat server Building a Java chat server Presented by developerworks, your source for great tutorials Table of Contents If you're viewing this document online, you can click any of the topics below to link directly

More information

Principles of Software Construction: Objects, Design, and Concurrency. Design Case Study: Stream I/O Some answers. Charlie Garrod Jonathan Aldrich

Principles of Software Construction: Objects, Design, and Concurrency. Design Case Study: Stream I/O Some answers. Charlie Garrod Jonathan Aldrich Principles of Software Construction: Objects, Design, and Concurrency Design Case Study: Stream I/O Some answers Fall 2014 Charlie Garrod Jonathan Aldrich School of Computer Science 2012-14 C Kästner,

More information

Socket Programming in C/C++

Socket Programming in C/C++ September 24, 2004 Contact Info Mani Radhakrishnan Office 4224 SEL email mradhakr @ cs. uic. edu Office Hours Tuesday 1-4 PM Introduction Sockets are a protocol independent method of creating a connection

More information

NETWORKING FEATURES OF THE JAVA PROGRAMMING LANGUAGE

NETWORKING FEATURES OF THE JAVA PROGRAMMING LANGUAGE 50-20-44 DATA COMMUNICATIONS MANAGEMENT NETWORKING FEATURES OF THE JAVA PROGRAMMING LANGUAGE John P. Slone INSIDE Java s Target Environment, Networking Basics, Java Networking Primitives, Connection-Oriented

More information

Domain Name System (DNS) Omer F. Rana. Networks and Data Communications 1

Domain Name System (DNS) Omer F. Rana. Networks and Data Communications 1 Domain Name System (DNS) Omer F. Rana Networks and Data Communications 1 What is a DNS Each institution on the internet has a host that runs a process called a Domain Name Server (also DNS!) It is not

More information

Computer Networks. Instructor: Niklas Carlsson Email: niklas.carlsson@liu.se

Computer Networks. Instructor: Niklas Carlsson Email: niklas.carlsson@liu.se Computer Networks Instructor: Niklas Carlsson Email: niklas.carlsson@liu.se Notes derived from Computer Networking: A Top Down Approach, by Jim Kurose and Keith Ross, Addison-Wesley. The slides are adapted

More information

CHAPTER 6. Transmission Control Protocol. 6.1 Overview

CHAPTER 6. Transmission Control Protocol. 6.1 Overview Reilly06.qxd 3/1/02 1:33 PM Page 141 CHAPTER 6 Transmission Control Protocol The Transmission Control Protocol (TCP) is a stream-based method of network communication that is far different from any discussed

More information

Chapter 10. A stream is an object that enables the flow of data between a program and some I/O device or file. File I/O

Chapter 10. A stream is an object that enables the flow of data between a program and some I/O device or file. File I/O Chapter 10 File I/O Streams A stream is an object that enables the flow of data between a program and some I/O device or file If the data flows into a program, then the stream is called an input stream

More information

JAVA - FILES AND I/O

JAVA - FILES AND I/O http://www.tutorialspoint.com/java/java_files_io.htm JAVA - FILES AND I/O Copyright tutorialspoint.com The java.io package contains nearly every class you might ever need to perform input and output I/O

More information

TITLE NETWORK PROGRAMMING (SECURED CLIENT-SERVER CHAT APPLICATION) A PROJECT REPORT PRESENTED ACHILE UGBEDE JOHN CE/2007/165

TITLE NETWORK PROGRAMMING (SECURED CLIENT-SERVER CHAT APPLICATION) A PROJECT REPORT PRESENTED ACHILE UGBEDE JOHN CE/2007/165 TITLE NETWORK PROGRAMMING (SECURED CLIENT-SERVER CHAT APPLICATION) A PROJECT REPORT PRESENTED BY ACHILE UGBEDE JOHN CE/2007/165 TO THE DEPARTMENT OF COMPUTER ENGINEERING IN FACULTY OF ENGINEERING CARITAS

More information

Network Programming TDC 561

Network Programming TDC 561 Network Programming TDC 561 Lecture # 1 Dr. Ehab S. Al-Shaer School of Computer Science & Telecommunication DePaul University Chicago, IL 1 Network Programming Goals of this Course: Studying, evaluating

More information

UNIX Sockets. COS 461 Precept 1

UNIX Sockets. COS 461 Precept 1 UNIX Sockets COS 461 Precept 1 Clients and Servers Client program Running on end host Requests service E.g., Web browser Server program Running on end host Provides service E.g., Web server GET /index.html

More information

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus 1. Purpose This assignment exercises how to write a peer-to-peer communicating program using non-blocking

More information

Chapter 2: Application layer

Chapter 2: Application layer Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic Mail SMTP, POP3, IMAP 2.5 DNS 2.6 P2P applications 2: Application Layer 1 Some network apps e-mail

More information

Computer Networks/DV2 Lab

Computer Networks/DV2 Lab Computer Networks/DV2 Lab Room: BB 219 Additional Information: http://ti.uni-due.de/ti/en/education/teaching/ss13/netlab Equipment for each group: - 1 Server computer (OS: Windows Server 2008 Standard)

More information

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2 SMTP-32 Library Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows Version 5.2 Copyright 1994-2003 by Distinct Corporation All rights reserved Table of Contents 1 Overview... 5 1.1

More information

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty("java.security.policy","../server.java.

ExempleRMI.java. // Fichier de defintion des droits et proprietes // System.setProperty(java.security.policy,../server.java. ExempleRMI.java import java.lang.*; import java.rmi.registry.*; import java.rmi.server.*; import java.io.*; import java.util.*; ExempleRMI.java import pkgexemple.*; public class ExempleRMI public static

More information

320341 Programming in Java

320341 Programming in Java 320341 Programming in Java Fall Semester 2014 Lecture 10: The Java I/O System Instructor: Slides: Jürgen Schönwälder Bendick Mahleko Objectives This lecture introduces the following - Java Streams - Object

More information

FILE I/O IN JAVA. Prof. Chris Jermaine cmj4@cs.rice.edu. Prof. Scott Rixner rixner@cs.rice.edu

FILE I/O IN JAVA. Prof. Chris Jermaine cmj4@cs.rice.edu. Prof. Scott Rixner rixner@cs.rice.edu FILE I/O IN JAVA Prof. Chris Jermaine cmj4@cs.rice.edu Prof. Scott Rixner rixner@cs.rice.edu 1 Our Simple Java Programs So Far Aside from screen I/O......when they are done, they are gone They have no

More information

Introduction to Socket programming using C

Introduction to Socket programming using C Introduction to Socket programming using C Goal: learn how to build client/server application that communicate using sockets Vinay Narasimhamurthy S0677790@sms.ed.ac.uk CLIENT SERVER MODEL Sockets are

More information

Transparent Redirection of Network Sockets 1

Transparent Redirection of Network Sockets 1 Transparent Redirection of Network Sockets 1 Timothy S. Mitrovich, Kenneth M. Ford, and Niranjan Suri Institute for Human & Machine Cognition University of West Florida {tmitrovi,kford,nsuri}@ai.uwf.edu

More information

Crash Course in Java

Crash Course in Java Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is

More information

Cross-platform TCP/IP Socket Programming in REXX

Cross-platform TCP/IP Socket Programming in REXX Cross-platform TCP/IP Socket programming in REXX Abstract: TCP/IP is the key modern network technology, and the various REXX implementations have useful, if incompatible interfaces to it. In this session,

More information

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab. Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

More information

Socket Programming. Srinidhi Varadarajan

Socket Programming. Srinidhi Varadarajan Socket Programming Srinidhi Varadarajan Client-server paradigm Client: initiates contact with server ( speaks first ) typically requests service from server, for Web, client is implemented in browser;

More information

FTP client Selection and Programming

FTP client Selection and Programming COMP 431 INTERNET SERVICES & PROTOCOLS Spring 2016 Programming Homework 3, February 4 Due: Tuesday, February 16, 8:30 AM File Transfer Protocol (FTP), Client and Server Step 3 In this assignment you will

More information

Lab 4: Socket Programming: netcat part

Lab 4: Socket Programming: netcat part Lab 4: Socket Programming: netcat part Overview The goal of this lab is to familiarize yourself with application level programming with sockets, specifically stream or TCP sockets, by implementing a client/server

More information

Introduction to Computer Networks

Introduction to Computer Networks Introduction to Computer Networks Chen Yu Indiana University Basic Building Blocks for Computer Networks Nodes PC, server, special-purpose hardware, sensors Switches Links: Twisted pair, coaxial cable,

More information

Manual. Programmer's Guide for Java API

Manual. Programmer's Guide for Java API 2013-02-01 1 (15) Programmer's Guide for Java API Description This document describes how to develop Content Gateway services with Java API. TS1209243890 1.0 Company information TeliaSonera Finland Oyj

More information

The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank on Page 8. Pages 7-8 can be removed from the exam.

The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank on Page 8. Pages 7-8 can be removed from the exam. CS326e Spring 2014 Midterm Exam Name SOLUTIONS UTEID The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank on Page 8. Pages 7-8 can be removed from the exam. 1. [4 Points]

More information

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk

www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling

More information

Transparent Redirection of Network Sockets 1

Transparent Redirection of Network Sockets 1 Transparent Redirection of Network Sockets Timothy S. Mitrovich, Kenneth M. Ford, and Niranjan Suri Institute for Human & Machine Cognition University of West Florida {tmitrovi,kford,nsuri@ai.uwf.edu.

More information

Java Fundamental Classes Reference

Java Fundamental Classes Reference Java Fundamental Classes Reference Mark Grand and Jonathan Knudsen O'REILLY Cambridge Köln Paris Sebastopol Tokyo v Table of Contents Preface xv 1. Introduction 1 1.1 The java.lang Package 2 1.2 The java.lang.reflect

More information

All rights reserved. Copyright in this document is owned by Sun Microsystems, Inc.

All rights reserved. Copyright in this document is owned by Sun Microsystems, Inc. J2ME CLDC API 1.0 Copyright 2000 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303 USA All rights reserved. Copyright in this document is owned by Sun Microsystems, Inc. Sun Microsystems,

More information