SQL Data Base Connection code

Imports System
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.SqlClient
Dim myConnection As System.Data.SqlClient.SqlConnection
Dim myCommand As System.Data.SqlClient.SqlCommand
Dim strSQL As String
myConnection = New SqlConnection("Data Source=MCANODE-102\MCA;Initial Catalog=master;Integrated Security=True")’master is database name,MCANODE_102\MCA hostname

        myConnection.Open()’Open the connection
        strSQL = "SELECT * FROM kar where id=12" ‘kar is tablename,id is field
        myCommand = New SqlCommand(strSQL, myConnection)
        Dim re As SqlDataReader = myCommand.ExecuteReader()
        While re.Read
            TextBox1.Text = re.GetString(2).ToString
        End While
       

        myConnection.Close()’Close the connection

RMI simple example




RMI simple example

Interface
            import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Calculator extends Remote
{
    public long addition(long a,long b) throws RemoteException;
    public long subtraction(long a,long b) throws RemoteException;
    public long multiplication(long a,long b) throws RemoteException;
    public long division(long a,long b) throws RemoteException;
}


Implementation

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class CalculatorImpl extends UnicastRemoteObject implements Calculator
{
    protected CalculatorImpl() throws RemoteException
    {
        super();
    }
    public long addition(long a, long b) throws RemoteException
    {
        return a+b;
    }
    public long subtraction(long a, long b) throws RemoteException
    {
        return a-b;
    }
    public long multiplication(long a, long b) throws RemoteException
    {
        return a*b;
    }
    public long division(long a, long b) throws RemoteException
    {
        return a/b;
    }
   
}



import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Calculator extends Remote
{
    public long addition(long a,long b) throws RemoteException;
    public long subtraction(long a,long b) throws RemoteException;
    public long multiplication(long a,long b) throws RemoteException;
    public long division(long a,long b) throws RemoteException;
}


Server
import java.rmi.Naming;

public class CalculatorServer
{
    CalculatorServer()
    {
        try
        {
            Calculator c = new CalculatorImpl();
            Naming.rebind("rmi://localhost:1099/CalculatorService", c);
        }
        catch (Exception e)
        {
            System.out.println("Exception is : "+e);
        }
    }
    public static void main(String[] args)
    {
        new CalculatorServer();
    }
}


Client
import java.rmi.Naming;

public class CalculatorClient
{
    public static void main(String[] args)
    {
        try
        {
            Calculator c = (Calculator) Naming.lookup("//127.0.0.1:1099/CalculatorService");
            System.out.println("Addition : "+c.addition(10,5));
            System.out.println("Subtraction : "+c.subtraction(10,5));
            System.out.println("Multiplication :"+c.multiplication(10,5)); 
                    System.out.println("Division : "+c. division(10,5));
        }
        catch (Exception e)
        {
            System.out.println("Exception is : "+e);
        }
    }
}


Compilation

javac Calculator.java

javac CalculatorImpl.java

javac CalculatorServer.java

javac CalculatorClient.java

rmic  CalculatorImpl

start rmiregistry


java CalculatorServer

java CalculatorClient

output

Addition : 15
Subtraction : 5
Multiplication :50
Division : 2

MULTI USER CHAT USING SOCKETS

Server program

 #include<stdio.h>
#include<sys/socket.h>
#include<netdb.h>
#include<string.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
 int sd,sd1,i,clilen,len,sport;
 struct sockaddr_in ser,cli;
 char smsg[20],rmsg[20];
printf("\n\t Enter the Port : ");
scanf("%d",&sport);
if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
{
  printf("\n\t Error in socket");
  return 0;
}
bzero(&ser,sizeof(ser));
ser.sin_family=AF_INET;
ser.sin_port=htons(sport);
ser.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sd,(struct sockaddr*)&ser,sizeof(ser)) <0)
{
  printf("\n\t Error in bind");
  return 0;
}
if(listen(sd,5) <0)
{
 printf("\n\t Error in Listen");
 return 0;
}
do
{
printf("\n\t Enter the client no to be communicate : ");
scanf("%d",&i);
 if(i==0)
   exit(0);
printf("\n\t Client %d is connected",i);
clilen=sizeof(cli);
if((sd1=accept(sd,(struct sockaddr*)&cli,&clilen)) <0)
{
 printf("\n\t Error in Accept");
 return 0;   }

 printf("\n\t Accepted ");
  do
 {
  recv(sd1,rmsg,20,0);
  printf("\n\t Clinet Msg Received : %s ",rmsg);
 printf("\n\t Enter Server String : ");
 scanf("%s",smsg);
 send(sd1,smsg,20,0);
 wait(20);
 } while((strcmp(smsg,"exit"))!=0);
} while(i!=0);
  close(sd);
}

Client :1  program

 #include<stdio.h>
#include<sys/socket.h>
#include<netdb.h>
#include<string.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
int sd,len,cport;
struct sockaddr_in ser;
char smsg[20],rmsg[20];
printf("\n\t Enter the Port : ");
scanf("%d",&cport);
if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
{
  printf("\n\t Error in socket");
  return 0;
}

bzero(&ser,sizeof(ser));
ser.sin_family=AF_INET;
ser.sin_port=htons(cport);
ser.sin_addr.s_addr=htonl(INADDR_ANY);

if(connect(sd,(struct sockaddr*)&ser,sizeof(ser)) <0)
{
  printf("\n\t Error in connect");
  exit(-1);
}

do
{

 printf("\n\t Enter the Client String :");
 scanf("%s",smsg);
 send(sd,smsg,20,0);
 wait(20);
 recv(sd,rmsg,20,0);
 printf("\n\t  Server Msg Received : %s ",rmsg);
}
while((strcmp(rmsg,"exit"))!=0);
close(sd);
}

Client :2  program

 #include<stdio.h>
#include<sys/socket.h>
#include<netdb.h>
#include<string.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
int sd,len,cport;
struct sockaddr_in ser;
char smsg[20],rmsg[20];
printf("\n\t Enter the Port : ");
scanf("%d",&cport);
if((sd=socket(AF_INET,SOCK_STREAM,0))<0)
{
  printf("\n\t Error in socket");
  return 0;
}

bzero(&ser,sizeof(ser));
ser.sin_family=AF_INET;
ser.sin_port=htons(cport);
ser.sin_addr.s_addr=htonl(INADDR_ANY);

if(connect(sd,(struct sockaddr*)&ser,sizeof(ser)) <0)
{
  printf("\n\t Error in connect");
  exit(-1);
}

do
{

 printf("\n\t Enter the Client String :");
 scanf("%s",smsg);
 send(sd,smsg,20,0);
 wait(20);
 recv(sd,rmsg,20,0);
 printf("\n\t  Server Msg Received : %s ",rmsg);
}
while((strcmp(rmsg,"exit"))!=0);
close(sd);
}


OUTPUT

SERVER

[11ca013@mcalinux network]$ cc 15mulser.c
[11ca013@mcalinux network]$ ./a.out

         Enter the Port : 3326

         Enter the client no to be communicate : 1
         Client 1 is connected
         Accepted
         Clinet Msg Received : hi
         Enter Server String : how_are_you
         Clinet Msg Received : i_am_fine
         Enter Server String : exit

         Enter the client no to be communicate : 2
         Client 2 is connected
         Accepted
         Clinet Msg Received : hi
         Enter Server String : how_are_you
         Clinet Msg Received : i_am_boss
         Enter Server String : exit

         Enter the client no to be communicate : 0
[11ca013@mcalinux network]$

CLIENT:1

[11ca013@mcalinux network]$ cc 15mulcli1.c
[11ca013@mcalinux network]$ ./a.out

         Enter the Port : 3326

         Enter the Client String :hi
          Server Msg Received : how_are_you
         Enter the Client String :i_am_fine
          Server Msg Received : exit

CLIENT:2

[11ca013@mcalinux network]$ cc 15mulcli2.c
[11ca013@mcalinux network]$  ./a.out

         Enter the Port : 3326

         Enter the Client String :hi

          Server Msg Received : how_are_you
         Enter the Client String :i_am_boss
          Server Msg Received : exit


SIMULATION OF ROUTING PROTOCOL (OSPF)

Program

#include<stdio.h>
#include<string.h>
int main()
{
int count,src_router,i,j,k,w,v,min;
int cost_matrix[100][100],dist[100],last[100];
int flag[100];
printf("\nENTER THE NO OF ROUTERS:");
scanf("%d",&count);
printf("\nENTER THE COST MATRIX VALUES:");
for(i=0;i<count;i++)
{
 for(j=0;j<count;j++)
{
printf("\n%d->%d:",i,j);
scanf("%d",&cost_matrix[i][j]);
if(cost_matrix[i][j]<0)
cost_matrix[i][j]=1000;
}
}


printf("\n\t The COST MATRIX is : \n ");
for(i=0;i<count;i++)
  {
 for(j=0;j<count;j++)
  printf("%d\t",cost_matrix[i][j]);
  printf("\n");
   }
printf("\n ENTER THE SOURCE ROUTER:");
scanf("%d",&src_router);
for(v=0;v<count;v++)
  {
flag[v]=0;
last[v]=src_router;
dist[v]=cost_matrix[src_router][v];
  }
 flag[src_router]=1;
for(i=0;i<count;i++)
{
min=1000;
for(w=0;w<count;w++)
      {
if(!flag[w])
if(dist[w]<min)
{
v=w;
min=dist[w];
      }
  }
flag[v]=1;
for(w=0;w<count;w++)
            {
if(!flag[w])
if((min+cost_matrix[v][w])<dist[w])
{
dist[w]=min+cost_matrix[v][w];
last[w]=v;
  }    }   }
for(i=0;i<count;i++)
{
printf("\n%d==>%d:PATH TAKEN:%d",src_router,i,i);
w=i;
while(w!=src_router)
{
printf("\n<--%d",last[w]);
w=last[w];
}
printf("\nSHORTEST PATH COST:%d\n",dist[i]);
}
return(0);
}











OUTPUT
[11ca013@mcalinux network]$ cc 16ospf.c
[11ca013@mcalinux network]$  ./a.out

ENTER THE NO OF ROUTERS:3

ENTER THE COST MATRIX VALUES:
0->0:100

0->1:1

0->2:3

1->0:1

1->1:100

1->2:1

2->0:1

2->1:1

2->2:100

         The COST MATRIX is :
 100    1       3
1       100     1
1       1       100

 ENTER THE SOURCE ROUTER:2

2==>0:PATH TAKEN:0
<--2
SHORTEST PATH COST:1

2==>1:PATH TAKEN:1
<--2
SHORTEST PATH COST:1

2==>2:PATH TAKEN:2

SHORTEST PATH COST:100



Your IP Address is:

Browser: