Docsity

Socking Programming - An Introduction Using Java | ISA 656, Study notes of Cryptography and System Security

Partial preview of the text

Download Socking Programming - An Introduction Using Java | ISA 656 and more Study notes Cryptography and System Security in PDF only on Docsity!

Socket Programming

An Introduction using Java

Assumptions



Familiar with network basics (i.e. TCP/IP)



Familiar with basics of programming in Java

Using a text editor



preferableIn a real project (school/work) an IDE would be



highlighting, contextual help etc, etc, etc…No auto-complete, project management tools, syntax



whole build cycle; including makeManual build tools (in many cases IDE take care of the

fi les)



command promptUsing a text editor, we need to compile using a

TRY:A hello world example

{ public class HelloWorldimport java.io.;/ * Some comment goes here /* { public static void main(String[] args) System.out.println("Hello World");

}

}



Look at HelloWorld.java



Make modi

fi cations to the code, re-compile

TRY: Compiling HelloWorld



We will compile our simple HelloWorld programs



We will introduce errors and analyze the output



javac HelloWorld.javaIn our case, we will simply compile using

Some popular Java based IDEs



Netbeans (opensource)



Eclipse (opensource)



BlueJ (designed for introductory teaching, opensource)



IntelliJ (payware, but those who use it say it is worth it)

What are sockets



TCP/IP protocol suite makes the internet possible



Sockets are an abstraction



Connection point to IP using either TCP or UDP



http://java.sun.com/docs/books/tutorial/networking/sockets/index.htmlLook at:

Connection vs. Connectionless



Comes down to TCP vs. UDP



Stream vs. Datagram



A simplistic view: Guarantee vs. Performance

Connection Initiation Diagram



Socket



ServerSocket



InputStream



OutputStream



BufferedReader/InputStreamReader



DataOutputStream

Useful Classes

API Docs



http://java.sun.com/j2se/1.4.2/docs/api/



Look for Socket related classes in java.net

TRY: Fetch URL Google.com



homepage.Write a simple client that will get the text for the Google



www.w3c.orgI will provide you with a sample client that does it for



http://ise.gmu.edu/~astavrou/courses/isa_656_F07/W3CClient.javaSample code located at: