Monday, November 29, 2010

System.Net.Sockets.Socket Class

System.Net.Sockets.Socket Class provides the basic functionality of a socket application.

  • Some important properties of System.Net.Sockets.Socket

Property Description
AddressFamily Gets the address family of the socket-the value is from the Socket.AddressFamily enumeration
Returns the amount of available data to read
Gets or sets the value which indicates whether the socket is in blocking mode or not
Returns the value that informs whether the socket is still connected with the remote host
Gets the local endpoint
Get the protocol type of the socket
Gets the remote endpoint of a socket
Gets the type of the socket

  • Some important methods of System.Net.Sockets.Socket

Method Description
Creates a new socket to handle the incoming connection request.
Associates a socket with the local endpoint for listening to incoming connections.
Forces the socket to close itself.
Establishes a connection with the remote host.
Returns the value of a SocketOption.
Sets low-level operating modes for the socket. This method provides low-level access to the underlying socket instance of the Socket class.
Places the socket in listening mode. This method is exclusive to server applications.
Receives data from a connected socket.
Determines the status of the socket.
Checks the status of one or more sockets.
Sends data to the connected socket.
Sets a SocketOption.
Disables send and receive on a socket.

Sunday, November 28, 2010

Publish Source Code in Blogger Using SyntaxHighlighter

  • In blogger under "Design" tab click "Edit HTML".
  • Copy following and paste it just before the </head> tag in the area under "Edit Template".
  • <link href="" rel="stylesheet" type="text/css"></link> <script language="javascript" src=""> <script language='javascript' src=''/>  </script>
  • Copy following and paste it in the same area as in the second step but this time paste it just before the </body> tag.
  • <script language="javascript"> dp.SyntaxHighlighter.BloggerMode(); dp.SyntaxHighlighter.HighlightAll('code'); </script>
  • Goto and copy the entire stylesheet paste it in the same area as step one and two, but this time paste it just before ]]<.
  • HTML Encode the source code using "HTML-encode a string".
  • Composing a blog post inside the "Edit HTML" editor,when you encounter a place where it is required to add the code snippet copy the encoded source code and paste it in between following tags.
  • <pre name="code" class="Cpp"> ….My code here… </pre>  

Saturday, November 27, 2010



  • Socket is one end of a two way communication link between two programs running on a network.
  • Data can be passed between different processes by connecting the two sockets together

Basic socket types

  • Stream Socket
    • Connection oriented sockets
    • Consists of a stream of bytes that can be bi-directional
    • Usage of stream sockets is a more reliable method than the usage of datagram sockets
  • Datagram sockets
    • AKA Connectionless sockets, no explicit connection is established
    • A message is sent to a specified socket and can be received appropriately from the specified socket
    • Usage of datagram sockets is reducing the overhead incurred by establishing an explicit connection

Row sockets

  • Generalized form of sockets called row sockets
  • Packet is passed directly to the application that needs it bypassing the mechanism by which the computer handles TCP/IP


  • Defined to solve the problem of communicating with multiple operations simultaneously

Sockets composed of
  • IP address of the machine
  • Port no used by TCP application

Socket numbers are unique across the entire internet as IP address is unique across the internet and the port no is unique on the individual machine. This enables process to communicate with another process across network based entirely on socket number.

Client Server applications uses sockets

  • Server waits for the connection from the client
  • Client initiates the connection with the server
  • Server should be already running before client tries to connect
  • Client must know the target address and the port no, tries to establish a connection with the server
  • Server accepts the connection
  • Server application creates a new socket to deal specifically with the connected client
  • Server and client communicate by reading from and writing to their respective sockets

Friday, November 26, 2010

Visual Studio Command Prompt

C# codes can be compiled using "Visual Studio Command Prompt". Most of the people facing difficulties when it comes to find this command prompt. It resides in "C:\Windows\System32" as cmd.exe. For windows7 users it is possible to search for it through the start menu typing "visual studio command prompt".

Assume test.cs,

How to compile

csc test.cs

How to execute


Tuesday, November 23, 2010

IP Header

• Version (Specifies the format of the IP packet header): 4 bits.

• IHL, Internet Header Length (Specifies the length of the IP packet header in 32 bit words. The minimum value for a valid header is 5): 4 bits.

• Differentiated Services (This field is defined in RFC 2474 and obsoletes the TOS field): 8 bits.

• Total length (Contains the length of the datagram). 16 bits.

• Identification (Used to identify the fragments of one datagram from those of another. The originating protocol module of an internet datagram sets the identification field to a value that must be unique for that source-destination pair and protocol for the time the datagram will be active in the internet system. The originating protocol module of a complete datagram clears the MF bit to zero and the Fragment Offset field to zero): 16 bits.

• Flags: 3 bits.

• Fragment Offset (Used to direct the reassembly of a fragmented datagram): 13 bits.

• TTL, Time to Live (A timer field used to track the lifetime of the datagram. When the TTL field is decremented down to zero, the datagram is discarded): 8 bits.

• Protocol (This field specifies the next encapsulated protocol): 8 bits.

• Header checksum (A 16 bit one's complement checksum of the IP header and IP options): 16 bits.

• Source IP address (IP address of the sender): 32 bits.

• Destination IP address (IP address of the intended receiver): 32 bits.


ARP (address resolution protocol) is used to translate protocol addresses to hardware interface addresses(mac).

ARP Header

• Hardware type: 16 bits.

• Protocol type: 16 bits.

• Hardware address length (Length of the hardware address in bytes.): 8 bits.

• Protocol address length (Length of the protocol address in bytes.): 8 bits.

• Opcode: 16 bits.

• Source hardware address: Variable length.

• Source protocol (mac) address: Variable length.

• Destination hardware (mac) address.: Variable length.

• Destination protocol address: Variable length.

Monday, November 22, 2010

Wireshark video tutorials

Wireshark is a free and open source software which is used for packet capturing and network analyzing... Download wireshark:

Here are some good video tutorials to get a basic understand of wireshark software...

Introduction to Wireshark (Part 1 of 3)

Cookies and Grabbing Passwords with Wireshark (Part 2 of 3)

Data Mining using Wireshark (Part 3 of 3)

Thursday, November 18, 2010

Bit further into lex

Consider the lex program given below (line.l) which adds line numbers in front of each line in a given text file and displays the output on standard output.

The use of lex variables and lex functions

yytext : The text of the matched pattern is stored in this variable. yytext is a char pointer.

yyin : Of the type FILE*. This points to the current file being parsed by the lexer.

yylex() : The function that starts the analysis. It is automatically generated by Lex.

What if there is no matching pattern to be found?
Any string matches and default action happens which means all the inputs are going to be printed in a way one at a time.


int lineno=1;



.*\n { printf("%5d %s",lineno++,yytext); }


main(int argc, char*argv[])

FILE *yyin;
return 0;


Compilation process

lex line.l
cc lex.yy.c -0 line -lfl


For this program it requires a a file as a command line argument. So a file should be provided in this stage.

./line filename

If it is needed to print the output in a file, just redirect the output to a text file like following.

./line > filename

Thursday, November 11, 2010

How to add external jar files in eclipse

1. Inside the "package explorer", Right click on the project which needs to add the external jar file and click on "properties".

2. In "java build path", inside "Libraries" tab choose the external jar file by clicking on "Add external JARs" button and click "OK".

Wednesday, November 3, 2010

Configuring Git on Windows

Create an account in

Create a project in there

Download and install following three programs in the given order

After finishing installations, Open git bash program and type the following command there (skip pass phrasing by entering). This process will generate a key.

ssh-keygen -C “” -t rsa

(give an email address instead of “”)

The key will be stored in a .ssh folder somewhere, usually in your user folder c:\\Documents and Settings\\Username\\.ssh on XP or c:\\Users\\Username\\.ssh on Windows7

Upload the key to codaset using the following way.
Myaccount > SSH keys then click on "upload new"

Open Git Extensions program

Click "clone repository"

Goto codaset account again and click on the project created, copy text under SSH tab

Now gain go to the clone window, paste it to the text area "repository to clone",give a desired destination and click ok

Goto the given destination folder and the project will be seen in there

Do the wanted changes to the project , go to the Git extensions again and open the repository been working on, under the command menu click on commit, stage the wanted files and click on "commit and push" to update in codaset so changes will be visible to everyone.