CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)

Slides:



Advertisements
Similar presentations
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Advertisements

Prepared By: Eng. Ola M. Abd El-Latif May/2010.  In this Lab we will answer the most frequently asked questions about programming sockets in Java. 
Socket Programming.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
1 Java Networking – Part I CS , Spring 2008/9.
WECPP1 Java networking Jim Briggs based on notes by Amanda Peart based on Bell & Parr's bonus chapter
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
Network Programming. The biggest difficult part in networking programming lies in understanding networking not in using java networking package. Since.
Client/Server In Java An Introduction to TCP/IP and Sockets.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
Process-to-Process Delivery:
Socket Programming in Java -First Step of Network Programming-
Greg Jernegan Brandon Simmons. The Beginning…  The problem Huge demand for internet enabled applications and programs that communicate over a network.
Babak Esfandiari (based on slides by Qusay Mahmoud)
Socket programming 1. getByName import java.net.*; public class GetHostName { public static void main (String args[]) { String host = "
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 21.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Vassil Roussev 2 A socket is the basic remote communication abstraction provided by the OS to processes. controlled by operating system.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
 TCP (Transport Control Protocol) is a connection-oriented protocol that provides a reliable flow of data between two computers.  TCP/IP Stack Application.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Chapter 2 Applications and Layered Architectures Sockets.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
© Lethbridge/Laganière 2005 Chap. 3: Basing Development on Reusable Technology The Client-Server Architecture A distributed system is a system in.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Sockets Sockets A socket is an object that encapsulates a TCP/IP connection There is a socket on both ends of a connection, the client side and the server.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
Networking Terminology: ISP (Internet service provider) – dialup, dsl, cable LAN (local area network) IP (internet protocol) address, eg
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
Java Sockets Tutorial Rahul Malik Nov 12, 2005.
CSI 3125, Preliminaries, page 1 Networking. CSI 3125, Preliminaries, page 2 Networking A network represents interconnection of computers that is capable.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Socket Programming in Java -First Step of Network Programming-
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 CSCD 330 Network Programming Winter 2016 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
Java Networking I IS Outline  Quiz #3  Network architecture  Protocols  Sockets  Server Sockets  Multi-threaded Servers.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
Network Programming. These days almost all devices.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Java 13. Networking public class SumTest {
Socket Programming Ameera Almasoud
Networking COMP
MCA – 405 Elective –I (A) Java Programming & Technology
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Network Programming Introduction
Process-to-Process Delivery:
Process-to-Process Delivery: UDP, TCP
Presentation transcript:

CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)

Socket Programming Sockets are interfaces that can "plug into" each other over a network. Once so "plugged in", the programs so connected communicate. Network communication can be done by exchanging some data through transmitting that data in a message between a socket in one process and another socket in another process. When messages are sent, the messages are queued at the sending socket until the underlying network protocol has transmitted them. When they arrive, the messages are queued at the receiving socket until the receiving process makes the necessary calls to receive them.

Socket Programming An Internet socket is identified by the operating system as a unique combination of the following: Protocol (TCP, UDP or raw IP) Local IP address Local port number Remote IP address (Only for established TCP sockets) Remote port number (Only for established TCP sockets)

Socket Programming Client-Server Model A client software process may initiate a communication session, while the server waits for requests from any client. Most business applications being written today use the client-server model. So do the Internet's main application protocols, such as HTTP, SMTP, Telnet, DNS, etc.

Socket Programming Client-Server Model

Socket Programming Open-Read-Write-Close Before a user process can perform network operations, it Opens a socket to specify and obtain permissions for the network communication. Once a socket is opened, the user process makes one or more calls to Read or Write data through the socket. After all transfer operations are complete, the user process calls Close to inform the operating system that it has finished using that socket.

Java Socket - Open Client class Socket This class implements client sockets (also called just "sockets"). public Socket(InetAddress address, int port) throws IOException address - the IP address. port - the port number.

Java Socket - Open Socket MyClient; try { MyClient = new Socket("Machine name", PortNumber); } catch (IOException e) { System.out.println(e); }

Java Socket – Open Server class ServerSocket This class implements server sockets. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester. public ServerSocket(int port) throws IOException port - the port number, or 0 to use any free port. public Socket accept() throws IOException Returns: the new Socket

Java Socket - Open Open a socket on the server side: ServerSocket MyService; try { MyServerice = new ServerSocket(PortNumber); } catch (IOException e) { System.out.println(e); } Listen for and accept connections from clients on the server side: Socket serviceSocket = null; try { serviceSocket = MyService.accept(); } catch (IOException e) { System.out.println(e); }

Java Socket - Read class DataInputStream A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream. public InputStream getInputStream() throws IOException Returns an input stream for this socket. public final String readLine() throws IOException Returns the next line of text from this input stream.

Java Socket - Read On the client side: DataInputStream input; try { input = new DataInputStream(MyClient.getInputStream()); } catch (IOException e) { System.out.println(e); } On the server side: DataInputStream input; try { input = new DataInputStream(serviceSocket.getInputStream()); } catch (IOException e) { System.out.println(e); }

Java Socket - Write class DataOutputStream A data output stream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in. public OutputStream getOutputStream() throws IOException Returns an output stream for writing bytes to this socket. public final void writeBytes(String s) throws IOException s - a string of bytes to be written.

Java Socket - Write DataOutputStream output; try { output = new dataOutputStream(MyClient.getOutputStream()); } catch (IOException e) { System.out.println(e); }

Java Socket - Close public void close() throws IOException Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created. If this socket has an associated channel then the channel is closed as well.

Java Socket - Close On the client side: try { output.close(); input.close(); MyClient.close(); } catch (IOException e) { System.out.println(e); } On the server side: try { output.close(); input.close(); serviceSocket.close(); MyService.close(); } catch (IOException e) {System.out.println(e);}

SMTP client – an example

Echo server – an example

HDB3: High Density Bipolar 3 Encoding: The encoding rules follow those for AMI, except that a sequence of four consecutive 0's are encoding using a special "violation" bit (V). This bit has the same polarity as the last 1-bit which was sent using the AMI encoding rule. When there are even 1-bits between two V bit, a refinement is to encode the four bits as B00V, where B is a balancing pulse. The value of B is assigned as + or -, which has the opposite polarity as the last 1-bit.

HDB3: High Density Bipolar 3 Encoding Message: AMI: HDB3: V V B 0 0 +V -1 +1

HDB3: High Density Bipolar 3 Decoding: Finds all V bits; then converts “B00V” and “000V” to “0000”. Converts -1 to 1.

Lab 4 The input to the encoding program is a string of 0 and 1 from the keyboard. The input binary string will be encoded by the encoding program to the HDB3 stream. The encoding program should send a “request-to-send” message to the decoding program and waiting for a “clear- to-send” message from the decoding program, before sending. The decoding program will send a “clear-to-send” message to the encoding program after receiving a “request-to-send” message from the encoding program.

Lab 4 The HDB3 stream will be transmitted to the decoding program through socket. After received the HDB3 stream, the decoding program will acknowledge the receipt to the encoding program. Then the decoding program will decode the HDB3 stream into its original format and print on the screen. The HDB3 stream is represented by the sequence of three characters, “+”, “-” and “0”, respectively meaning the positive pulse, negative pulse, and no-line-signal.

Lab 4 You should try to use two computers to simulate the sender and receiver You should try to see whether other group’s receiving program can understand what you sent You should also try to see whether your receiving program can understand what other group sent.