Skip to main content

Posts

Showing posts from November, 2015

Network Programming - Part 3 (I)

Here's a quick and fun code that you can try on. We know that the port no spans from 0 - 65535. So lets loop through that range and find the active ports in the system. This is called a Port Scanner .  There are no steps to do this. Just make a loop and try to establish a connection . Implementation 01 import java.net.Socket ; public class MyPortScanner { public static void main ( String [] args ) { for ( int i = 0 ; i < 65535 ; i ++) { try { Socket ClientSoc = new Socket ( "localhost" , i ); System . out . println ( "Port " + i + " is active" ); ClientSoc . close (); } catch ( Exception e ) { System . out . println ( "Nope nothing on " + i + " port" ); } } } } The result I got was interesting. FYI this takes a longer time to finish scanning all 65535 ports. S...

Network Programming - Part 3

Last time we did make a server and connected using Telnet client. This time we are going to create a client using Java and try to connect to our earlier made simple server O key, Lets go straight to the coding part since there is no much to discuss. As creating the simple server this too has 3 steps. Opening the client  socket Create I/O stream (Read and write). Perform Communication and finally Close Socket So few things to remember from the earlier post. The server was created in the localhost and the port was 9000. Here is the code for Simple Client program.  import java.io.BufferedReader ; import java.io.InputStream ; import java.io.InputStreamReader ; import java.net.Socket ; public class MySimpleClient { public static void main ( String [] args ) { try { Socket ClientSoc = new Socket ( "localhost" , 9000 ); //Step1: Opening Client Socket InputStream is = ClientSoc . getIn...

Network Programming - Part 2

Okay, Continuing the  part 01 of this set. Let's get on with the practical side. Here I'll be using Java as the language and lets look at socket Programming. First things first some analogies What is a socket ? Socket is an end point actually. This end point need to be there for some communication to happen. If not the sender will not know where to  connect or not. Socket is the combination of the IP address and the Port no. the IP address determines the computer and the Port determines the Protocol and the application. Then what is a Port ? When an application runs on the computer a specific address is located for it. This specific address or the PORT can ether be TCP or UDP (Two Transport layer protocols). A port can have any number between 0 - 65,535. The port numbers below 1024 are most frequently used so if you are creating a custom application just use something above 1024.  TCP vs UDP TCP is for Transmission Control Prot...

Network Programming - Part 1

Starting off with Network Programming I thought of discussing basics and the environment for the Network Programming. Why Network Programming? With the advancement of Technology and the ground breaking innovations we have come to a point that most of the thing we do are inter connected with each other. This is applicable for programs as well. Most of the programs we use has two modes now a days. Offline and Online. There for we can say that Programs are Network Aware. For example: Playing Dota 2 or LoL online. real time updates in servers, real time stock update etc. Lets talk about few of the simple things that can be done using a Network Program. A Network Program can retrieve data from a remote location as well as vise versa. Other than that if we talk about it further more, it allows peer-to peer interaction which supports us in chats, messaging, video conferencing etc.Another thing is Spiders in web searchin...