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("www.dei.uc.pt"); 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

Groupware: servers and clients. IAT 351 Week11 Lecture Lyn Bartram

Groupware: servers and clients. IAT 351 Week11 Lecture Lyn Bartram Groupware: servers and clients IAT 351 Week11 Lecture 2 19.03.2008 Lyn Bartram lyn@sfu.ca Today s agenda What is groupware? How do we build it? Networking and sockets Servers and clients Assignment 5 (

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

Networking Support In Java

Networking Support In Java Networking Support In Java Networking II Department of Computer Science University of Maryland, College Park Client/Server Model Overview Client/Server Programming Networking in Java Java Networking API

More information

JAVA - NETWORKING. Socket Programming: This is most widely used concept in Networking and it has been explained in very detail.

JAVA - NETWORKING. Socket Programming: This is most widely used concept in Networking and it has been explained in very detail. http://www.tutorialspoint.com/java/java_networking.htm JAVA - NETWORKING Copyright tutorialspoint.com The term network programming refers to writing programs that execute across multiple devices computers,

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

Java API Essentials (Part II) Web Languages Course 2009 University of Trento

Java API Essentials (Part II) Web Languages Course 2009 University of Trento Java API Essentials (Part II) Web Languages Course 2009 University of Trento Lab Objective More exercises on Object serialization Client-Server application through sockets Refresh basic Java concepts on

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

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

Java Network Programming. Why Java? Crash Course in Java. First Program: Simp.java. CSCE515 Computer Network Programming

Java Network Programming. Why Java? Crash Course in Java. First Program: Simp.java. CSCE515 Computer Network Programming CSCE 515: Computer Network Programming ------ Java Network Programming reference: Dave Hollinger Wenyuan Xu Department of Computer Science and Engineering University of South Carolina Java Network Programming

More information

Topics. 1. Network & IP 2. TCP Sockets 3. UDP Sockets CDA FS13 2

Topics. 1. Network & IP 2. TCP Sockets 3. UDP Sockets CDA FS13 2 Java networking Carlo U. Nicola, IMVS With extracts from slides/publications of : Dominik Gruntz, IMVS and from the book of K.J. Calvert and M.J. Donahoo TCP in Java Topics 1. Network & IP 2. TCP 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

TCP Sockets. Multithreading. But first... Overview of Multithreading in Java. Background on Threads

TCP Sockets. Multithreading. But first... Overview of Multithreading in Java. Background on Threads But first... Background on Threads Overview of Multithreading in Java Multithreading Java has build-in support for concurrent programming. This enables you to have multiple flows of control, represented

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

Networking Support In Java 2

Networking Support In Java 2 Networking Support In Java 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park Overview Networking Background Concepts Network applications Java s objected-oriented

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

SSC - Communication and Networking Java Socket Programming (I)

SSC - Communication and Networking Java Socket Programming (I) SSC - Communication and Networking Java Socket Programming (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC Outline Outline of Topics Sockets and Socket-based

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

Previously. Networking 2. Outline. TCP Client Side. Where s my server? Java Servers

Previously. Networking 2. Outline. TCP Client Side. Where s my server? Java Servers G52APR Java Application programming Networking 2 Michael Li http://www.cs.nott.ac.uk/~jwl/g52apr Previously Brief introduction to networking in Java What is IP and port How to find IP addresses (DNS lookup)

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

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

Internet Technology. 02r. Programming with Sockets Paul Krzyzanowski. Rutgers University. Spring 2013

Internet Technology. 02r. Programming with Sockets Paul Krzyzanowski. Rutgers University. Spring 2013 Internet Technology 02r. Programming with Sockets Paul Krzyzanowski Rutgers University Spring 2013 February 7, 2013 2013 Paul Krzyzanowski 1 Sample Client-Server Program To illustrate programming with

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

File Handling. Reading Character from File

File Handling. Reading Character from File File Handling The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent an input source and an output destination. The stream

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

goal: learn how to build client/server applications that communicate using sockets socket: dropbox between application process and endend-transport

goal: learn how to build client/server applications that communicate using sockets socket: dropbox between application process and endend-transport Socket programming goal: learn how to build client/server applications that communicate using sockets socket: dropbox between application process and endend-transport protocol application process socket

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

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

Outline. Introduction to Network Programming (java.net) Networking in Java Browsing (www) Custom networking (browsing)

Outline. Introduction to Network Programming (java.net) Networking in Java Browsing (www) Custom networking (browsing) Outline Introduction to Programming (java.net) Mazen.Malek.Shiaa@item.ntnu.no Applets All what you need about URLs Socket programming Implementation of client and server programs Datagrams Sources: 1.

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

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

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

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

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

Introduction to Java Sockets and. CIT Concurrency RMI

Introduction to Java Sockets and. CIT Concurrency RMI Introduction to Java Sockets and RMI Basic Concepts TCP versus UDP over IP Transmission Control Protocol, User Datagram Protocol, Internet Protocol Reliable versus unreliable packet delivery Reliable =

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

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

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

Java Support for developing TCP Network Based Programs

Java Support for developing TCP Network Based Programs Java Support for developing TCP Network Based Programs 1 How to Write a Network Based Program (In Java) As mentioned, we will use the TCP Transport Protocol. To communicate over TCP, a client program and

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

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

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

TCP/IP Transmission Control Protocol / Internet Protocol

TCP/IP Transmission Control Protocol / Internet Protocol TCP/IP Transmission Control Protocol / Internet Protocol Based on Notes by D. Hollinger 1 Topics IPv6 TCP Java TCP Programming 2 IPv6 availability Generally available with (new) versions of most operating

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

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

Internet Socket. Socket Programming (C/Java) Simple Client-Server Example. Client-Server Architecture. Ying Cai Lecture 2. CS587x

Internet Socket. Socket Programming (C/Java) Simple Client-Server Example. Client-Server Architecture. Ying Cai Lecture 2. CS587x Internet Socket Socket Programming (C/Java) Lecture 3 Department of Computer Science Iowa State University Socket provides an interface to TCP/UDP Allow programs to write networking applications Socket

More information

JAVA I/O. Professeur Patrick BELLOT. TELECOM ParisTech

JAVA I/O. Professeur Patrick BELLOT. TELECOM ParisTech JAVA I/O Professeur Patrick BELLOT TELECOM ParisTech The notion of stream I/O in JAVA are based on the notion of stream. Input streams. Output streams. Streams allow to read from / write to: Disk files

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

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

Lecture 4. Java I/O. Some useful classes in the java.io package. I/O buffering. Bit-by-bit I/O. Reading: online documentation of the java.

Lecture 4. Java I/O. Some useful classes in the java.io package. I/O buffering. Bit-by-bit I/O. Reading: online documentation of the java. Lecture 4 Java I/O Some useful classes in the java.io package I/O buffering Bit-by-bit I/O Reading: online documentation of the java.io package Page 1 of 40 A quick tour of the java.io package The java.io

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

This class allows the random movement of the file pointers. The file pointer can be moved back and forth.

This class allows the random movement of the file pointers. The file pointer can be moved back and forth. RandomAccessFile This class allows the random movement of the file pointers. The file pointer can be moved back and forth. Constructor: RandomAccessFile(String name, String mode) Creates a random access

More information

Networking Code. Jeffrey Miller, Ph.D. CSCI 201L USC CSCI 201L

Networking Code. Jeffrey Miller, Ph.D. CSCI 201L  USC CSCI 201L Networking Code CSCI 201L Jeffrey Miller, Ph.D. HTTP://WWW-SCF.USC.EDU/~CSCI201 USC CSCI 201L Outline Server Networking Client Networking Program USC CSCI 201L 2/11 Server Software A server application

More information

Java I/O. The Cheat Sheet

Java I/O. The Cheat Sheet Java I/O The Cheat Sheet Reading and Wri5ng The basic architecture of Java IO is pluggable. The idea is to have some very simple classes do very simple IO, and then use those simple classes in a variety

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

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

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

Android Overview. Dongsu Han

Android Overview. Dongsu Han Android Overview Dongsu Han 1 Outline Java network programming overview Android Overview Android Emulator Overview Project Overview Getting Started 2 Java Network Programming Java.net.* programming model

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

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

! "# $%&'( ) * ).) "%&' 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

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

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

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

A Simple Echo Server. Java Networking -- Socket. A Simple Echo Server (cont'd) Test the EchoServer with Telnet

A Simple Echo Server. Java Networking -- Socket. A Simple Echo Server (cont'd) Test the EchoServer with Telnet Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated. Client socket class: Socket an endpoint for communication

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

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

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

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

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

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

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

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

Programming Assignment: Development of a Proxy Cache

Programming Assignment: Development of a Proxy Cache Programming Assignment: Development of a Proxy Cache La prova avrà una valutazione da 0 a 3 punti da aggiungere alla media dell esito delle due prove di esonero scritte. La gestione dei thread non è da

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

CS11 Java. Fall Lecture 6

CS11 Java. Fall Lecture 6 CS11 Java Fall 2014-2015 Lecture 6 Today s Topics! Lab 6: Web Crawler!! Java Sockets API! String operations This Week s Assignment! Build a simple web-crawler " Connect to a web server " Send an HTTP request

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

Stream I/O and Files 14

Stream I/O and Files 14 Stream I/O and Files 14 Course Map This module discusses the stream I/O mechanism used for files, sockets, and other sources of data. Getting Started The Java Programming Language Basics Identifiers, Keywords,

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

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

1.00 Lecture 23. Streams

1.00 Lecture 23. Streams 1.00 Lecture 23 Input/Output Introduction to Streams Exceptions Reading for next time: Big Java 19.3-19.4 Streams Java can communicate with the outside world using streams Picture a pipe feeding data into

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

Java I/O. Università di Modena e Reggio Emilia Prof. Nicola Bicocchi

Java I/O. Università di Modena e Reggio Emilia Prof. Nicola Bicocchi Java I/O Università di Modena e Reggio Emilia Prof. Nicola Bicocchi (nicola.bicocchi@unimore.it) Java I/O Stream Buffer File StringTokenizer, StreamTokenizer SerializaAon Stream All I/O operaaons rely

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

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

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

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

Java I/O and Networking

Java I/O and Networking Slide 1 Lecture 3 Java I/O and Networking The main topic of this lecture is the way Java deals with network connections. Java is billed as being "the language of the Internet" and therefore one would expect

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

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

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

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

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

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