110 likes | 185 Views
ITEC 350 Homework 2. Socket Programming. API available to programs. Application Programming Interface (API) to TCP & UDP “Sockets” Two Modes: Datagram (DGRAM) Stream (INET) A socket is defined by an IP address and a port number. Application Program. Stream. Dgram.
E N D
ITEC 350 Homework 2 Socket Programming
API available to programs • Application Programming Interface (API) to TCP & UDP • “Sockets” • Two Modes: • Datagram (DGRAM) • Stream (INET) • A socket is defined by an IP address and a port number Application Program Stream Dgram TCP | UDP Transport Layer
Socket Programming – HW02 • Writing programs in Java can give students great insight into sockets, IP addresses, ports, etc. • If you have had ITEC 120/220 • Then you know all about java stream io (BufferedReader, BufferedWriter) • All you need is java.net package • If you have _not_ had ITEC 120/220 • you may use a programming language like C, C++, etc. • Or, if you have had no programming language that supports sockets, come see me in office hours.
java.net • The “real” .net … not that other M$.NET • Packages: what Java calls collections of classes • .net is a package – containing classes: • Socket, ServerSocket for TCP streams • DatagramSocket for UDP datagrams
Server Client Create a ServerSocket object for port 4444 Open a connection on port 4444 Using ServerSocket.accept, wait for a client to open a connection Wait for user to type something If user types only CR, exit else When a client opens a connection, the accept method has returned a copy of the client socket. Create a BufferedReader for this object. Using getOutputStream() method create PrintWriter object. Send client text to server Wait for server response Wait for client to type something Echo server response to cmdwin for client Echo client text to cmdwin for server. Accept server response from keyboard Send server text over socket to client • We will implement the following flowcharts
Note • this is *NOT* the standard Echo server that is widely found on the web. • You must have echo going in both directions. • Java Programming, but as a last resort C or C++ • If you only know C, C++ • Let me know via email
Submission • Save your source codes and a ReadMe.doc file to RU03 folder of your dropbox • The ReadMe.doc file must include: • Your name • File names of your source codes and descriptions of each files. • Executing Instruction • Length: Less than 3 pages