Accounts 2 Mark Question with Answers
Accounting life Cycle is contains the components of financial activities of the organization,
such as Journal, Ledger, Trial Balance, Profit and Loss A/c and Balance Sheet.
CREATION OF BASE TABLES AND VIEWS
SYNTAX
CREATE TABLE
EXAMPLE
SQL> create table studentlak(regno number(10),
2 name varchar(15),
3 dob date,
4 address varchar(50),
5 primary key(regno));
Table created.
DESCRIPTION
SYNTAX
DESC
EXAMPLE
SQL> DESC STUDENTLAK;
Name Null? Type
REGNO NOT NULL NUMBER(10)
NAME VARCHAR2(15)
DOB DATE
ADDRESS VARCHAR2(50)
INSERT VALUES
SYNTAX
INSERT INTO table_name(column1,column2….)VALUES (value1,value2..);
EXAMPLE
SQL> insert into studentlak values(®no,'&name','&dob','&address');
Enter value for regno: 100
Enter value for name: LAKSHMI
Enter value for dob: 01-MAY-1988
Enter value for address: NO.32 PANDIAN ST, R.M.K NAGAR CHENNAI-48
old 1: insert into studentlak values(®no,'&name','&dob','&address')
new 1: insert into studentlak values(100,'LAKSHMI','01-MAY-1988','NO.32 PANDIAN ST, R.M.K NAGAR CH
1 row created.
SQL> /
Enter value for regno: 101
Enter value for name: KUMAR
Enter value for dob: 13-MAR-1990
Enter value for address: NO.50 RANIPET, VELLORE
old 1: insert into studentlak values(®no,'&name','&dob','&address')
new 1: insert into studentlak values(101,'KUMAR','13-MAR-1990','NO.50 RANIPET, VELLORE')
1 row created.
SQL> /
Enter value for regno: 103
Enter value for name: SAHANA
Enter value for dob: 26-MAR-1990
Enter value for address: NEW MAIN ROAD VIRUDHUNAGAR
old 1: insert into studentlak values(®no,'&name','&dob','&address')
new 1: insert into studentlak values(103,'SAHANA','26-MAR-1990','NEW MAIN ROAD VIRUDHUNAGAR')
1 row created.
SELECT TABLE
SYNTAX
1. SELECT * FROM
2. SELECT
EXAMPLE
SQL> SELECT * FROM STUDENTLAK;
REGNO NAME DOB ADDRESS
100 LAKSHMI 01-MAY-88 NO.32 PANDIAN ST, R.M.K NAGAR CHENNAI-48
101 KUMAR 13-MAR-90 NO.50 RANIPET, VELLORE
103 SAHANA 26-MAR-90 NEW MAIN ROAD VIRUDHUNAGAR
SQL> SELECT regno, name FROM STUDENTLAK;
REGNO NAME
100 LAKSHMI
101 KUMAR
103 SAHANA
ALTER TABLE
ADD Column
SYNTAX
ALTER TABLE
EXAMPLE
SQL> alter table studentlak add(phno number(10),phno1 number(10));
Table altered.
SQL> desc studentlak;
Name Null? Type
REGNO NOT NULL NUMBER(10)
NAME VARCHAR2(15)
DOB DATE
ADDRESS VARCHAR2(50)
PHNO NUMBER(10)
PHNO1 NUMBER(10)
RENAME A TABLE
SYNTAX
ALTER TABLE
EXAMPLE
SQL> alter table studentlak rename to studentlakshmi;
Table altered.
SQL> select * from studentlakshmi;
REGNO NAME DOB ADDRESS
100 LAKSHMI 01-MAY-88 NO.32 PANDIAN ST, R.M.K NAGAR CHENNAI-48
101 KUMAR 13-MAR-90 NO.50 RANIPET, VELLORE
103 SAHANA 26-MAR-90 NEW MAIN ROAD VIRUDHUNAGAR
UPDATE Column Values
SYNTAX
Update
EXAMPLE
SQL> alter table studentlakshmi add(phno1 NUMBER(10));
Table altered.
SQL> UPDATE STUDENTLAKSHMI SET PHNO='9440001250' WHERE REGNO=100;
1 row updated.
SQL> UPDATE STUDENTLAKSHMI SET PHNO='125469871' WHERE REGNO=101;
1 row updated.
SQL> UPDATE STUDENTLAKSHMI SET PHNO='9440001233' WHERE REGNO=103;
· DROP Column
SYNTAX
Alter table
EXAMPLE
SQL> ALTER TABLE STUDENTLAKSHMI DROP COLUMN ADDRESS;
Table altered.
SQL> SELECT * FROM STUDENTLAKSHMI;
REGNO NAME DOB PHNO PHNO1
100 LAKSHMI 01-MAY-88 9440001250 9785649870
101 KUMAR 13-MAR-90 125469871 9785333000
103 SAHANA 26-MAR-90 9440001233 9785322111
TRUNCATE TABLE
SQL>Create table emp1(eno number(3),ename varchar2(25));
Table Created
SQL> TRUNCATE TABLE EMP1;
Table truncated.
SQL> SELECT * FROM EMP1;
no rows selected
DROP TABLE
SQL> DROP TABLE EMP1;
Table dropped.
SQL> DESC EMP1;
ERROR:
ORA-04043: object EMP1 does not exist
TO CREATE A VIEW
SYNTAX
CREATE OR REPLACE view< tablename>as SELECT coulumn1=”” where {condition};
EXAMPLE
SQL> create or replace view new as select * from STUDENTLAKSHMI;
View created.
SQL> SELECT * FROM NEW;
REGNO NAME DOB PHNO PHNO1
100 LAKSHMI 01-MAY-88 9440001250 9785649870
101 KUMAR 13-MAR-90 125469871 9785333000
103 SAHANA 26-MAR-90 9440001233 9785322111
SQL> SELECT * FROM STUDENTLAKSHMI;
REGNO NAME DOB PHNO PHNO1
100 LAKSHMI 01-MAY-88 9440001250 9785649870
101 KUMAR 13-MAR-90 125469871 9785333000
103 SAHANA 26-MAR-90 9440001233 9785322111
INSERT THE VALUES INTO VIEW (new) TABLE
SQL> insert into new values(®no,'&name','&dob',&phno,&phno1);
Enter value for regno: 3060
Enter value for name: hema
Enter value for dob: 25-oct-1980
Enter value for phno: 9874563214
Enter value for phno1: 9874563218
old 1: insert into new values(®no,'&name','&dob',&phno,&phno1)
new 1: insert into new values(3060,'hema','25-oct-1980',9874563214,9874563218)
1 row created.
SQL> /
Enter value for regno: 3061
Enter value for name: hemalatha
Enter value for dob: 22-feb-1977
Enter value for phno: 9825647584
Enter value for phno1: 1258963478
old 1: insert into new values(®no,'&name','&dob',&phno,&phno1)
new 1: insert into new values(3061,'hemalatha','22-feb-1977',9825647584,1258963478)
1 row created.
SQL> select * from new;
REGNO NAME DOB PHNO PHNO1
---------- --------------- --------- ---------- ----------
100 LAKSHMI 01-MAY-88 9440001250 9785649870
101 KUMAR 13-MAR-90 125469871 9785333000
103 SAHANA 26-MAR-90 9440001233 9785322111
3060 hema 25-OCT-80 9874563214 9874563218
3061 hemalatha 22-FEB-77 9825647584 1258963478
SQL> create or replace view new1 as select * from studentlakshmi with read only;
View created.
SQL> insert into new1 values(®no,'&name','&dob',&phno,&phno1);
Enter value for regno: 300
Enter value for name: lak
Enter value for dob: 30-oct-1985
Enter value for phno: 2589631478
Enter value for phno1: 9632587415
old 1: insert into new1 values(®no,'&name','&dob',&phno,&phno1)
new 1: insert into new1 values(300,'lak','30-oct-1985',2589631478,9632587415)
insert into new1 values(300,'lak','30-oct-1985',2589631478,9632587415)
*
ERROR at line 1:
ORA-01733: virtual column not allowed here
SQL> drop view new1;
View dropped.
Bank Operation Using RMI
Interface File
import java.rmi.*;
public interface BankIntf extends Remote
{
int withdraw(int a,int amt)throws RemoteException;
int deposit(int b,int amt)throws RemoteException;
int balance(int amt)throws RemoteException;
}
Implementation File
import java.rmi.*;
import java.rmi.server.*;
public class BankImpl extends UnicastRemoteObject implements BankIntf
{
public BankImpl()throws RemoteException
{}
public int withdraw(int a,int amt)throws RemoteException
{
amt=amt-a;
return(amt);
}
public int deposit(int b,int amt)throws RemoteException
{
amt=amt+b;
return(amt);
}
public int balance(int amt)throws RemoteException
{
return(amt);
}
}
Server
import java.rmi.*;
public class BankServer
{
public static void main(String args[])
{
try
{
BankImpl bankimpl=new BankImpl();
Naming.rebind("BankServer",bankimpl);
System.out.println("Serevr is ready");
}
catch(Exception e)
{
System.out.println("Exception :"+e);
}
}
}
Client
import java.io.*;
import java.rmi.*;
public class BankClient
{
public static void main(String args[])
{
int ch;
try
{
String bankserverURL="rmi://"+args[0]+"/BankServer";
BankIntf bankintf=(BankIntf)Naming.lookup(bankserverURL);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nEnter the UserName:");
String s=br.readLine();
System.out.println("\nEnter the Account Number:");
int ac=Integer.parseInt(br.readLine());
System.out.println("\nEnter the Initial Amount:");
int amt=Integer.parseInt(br.readLine());
do
{
System.out.println("\n\t1.Withdraw\n\t2.Deposit\n\t3.Balance\n\t4.Exit");
System.out.println("\nEnter your choice:");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("\nEnter amount of Withdraw:");
int wd=Integer.parseInt(br.readLine());
System.out.println("\nUserName:"+s);
System.out.println("Account Number:"+ac);
if(wd>amt)
System.out.println("Balance less unable to proceed withdraw");
else
{
amt=bankintf.withdraw(wd,amt);
System.out.println("Balance:"+amt);
}
break;
case 2:
System.out.println("\nEnter amount of deposit:");
int dp=Integer.parseInt(br.readLine());
System.out.println("\nUserName:"+s);
System.out.println("Account Number:"+ac);
amt=bankintf.deposit(dp,amt);
System.out.println("Balance:"+amt);
break;
case 3:
System.out.println("\nUserName:"+s);
System.out.println("Account Number:"+ac);
amt=bankintf.balance(amt);
System.out.println("Balance:"+amt);
break;
}
}while(ch<4);
} catch(Exception e)
{
System.out.println("Exception :"+e);
}
}
}
Steps to compile RMI
C:\set path=c:\jdk1.5\bin;
C:\jdk1.5\bin>javac BankIntf.java
C:\jdk1.5\bin>javac BankImpl.java
C:\jdk1.5\bin>javac BankServer.java
C:\jdk1.5\bin>javac BankClient.java
C:\jdk1.5\bin>rmic BankImpl
C:\jdk1.5\bin>start rmiregistry
C:\jdk1.5\bin>java BankServer
Serevr is ready
Open New Command Prompt
C:\set path=c:\jdk1.5\bin;
C:\jdk1.5\bin>java BankClient 170.100.40.37
Enter the UserName:Jaya
Enter the Account Number:100
Enter the Initial Amount:5000
1.Withdraw
2.Deposit
3.Balance
4.Exit
Enter your choice:1
Enter amount of Withdraw:1000
UserName:Jaya
Account Number:100
Balance:4000
1.Withdraw
2.Deposit
3.Balance
4.Exit
Enter your choice:2
Enter amount of deposit:6000
UserName:Jaya
Account Number:100
Balance:10000
1.Withdraw
2.Deposit
3.Balance
4.Exit
Enter your choice:3
UserName:Jaya
Account Number:100
Balance:10000
1.Withdraw
2.Deposit
3.Balance
4.Exit
Enter your choice:4
MULTI USER CHAT
SOURCE CODE
SERVER
#include “stdio.h “
#include “sys/types.h “
#include “sys/socket.h “
#include “netinet/in.h “
#define MAXSIZE 25
main()
{
system("clear");
struct sockaddr_in ss_addr, c_addr,c1_addr, c2_addr ;
int sockfd, rval;
socklen_t addr_len, addr_len1;
char buff[MAXSIZE], buff1[MAXSIZE];
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == -1 )
printf("socket(logical port) creation error");
ss_addr.sin_family = AF_INET;
ss_addr.sin_port = htons(6919);
ss_addr.sin_addr.s_addr = htonl(INADDR_ANY);
rval = bind(sockfd, (struct sockaddr*) &ss_addr, sizeof(ss_addr));
if (rval == -1)
{
printf( "Binding error");
close(sockfd);
}
else
{
addr_len = sizeof(c_addr);
addr_len1 = sizeof(c1_addr);
rval=recvfrom(sockfd,buff,sizeof(buff), 0, (struct sockaddr*)&c_addr,&addr_len );
if (rval == -1)
printf("while recving from 1st problem.");
puts(buff);
rval = recvfrom(sockfd, buff1, sizeof(buff1), 0, (struct sockaddr*)&c1_addr,&addr_len1 );
puts(buff1);
while(1)
{
rval= recvfrom(sockfd,buff1,sizeof(buff1), 0, (struct sockaddr*)&c1_addr, &addr_len1 );
if (rval == -1)
{
printf("while recving from 2nd problem.");
close(sockfd);
}
puts(buff1);
rval = sendto(sockfd, buff1, sizeof(buff1), 0, (struct sockaddr*)&c_addr, addr_len );
if (rval == -1)
printf("while sending from server to 1st client problem.");
// For Client 1
rval = recvfrom(sockfd, buff, sizeof(buff), 0, (struct sockaddr*)&c_addr, &addr_len );
if (rval == -1)
{
printf("while recving from 1st problem.");
close(sockfd);
}
puts(buff);
rval = sendto(sockfd, buff, sizeof(buff), 0, (struct sockaddr*)&c1_addr, addr_len1 );
if (rval == -1)
{
printf("while sending from server to 2nd client problem.");close(sockfd);
}
if (rval == -1)
{
printf("breaking from loop ");
close(sockfd);
break;
}
} // while end
}
close(sockfd);
}
CLIENT1
#include “sys/types.h “
#include “sys/socket.h “
#include “netinet/in.h “
#include “stdio.h “
#include “string.h “
#define MAXSIZE 25
main()
{
system("clear");
struct sockaddr_in c_addr, s1_addr;
int sockfd, rval;
socklen_t addr_len;
char buff[MAXSIZE];
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == -1)
printf("Error while socket creation");
s1_addr.sin_family = AF_INET;
s1_addr.sin_port = htons(6919);
s1_addr.sin_addr.s_addr = inet_addr("127.0.0.1") ;
read(0,buff,sizeof(buff));
rval = sendto(sockfd, buff, sizeof(buff), 0, (struct sockaddr *)&s1_addr, sizeof(s1_addr));
if (rval == -1)
{
printf("While sending problem");
close(sockfd);
}
while(1)
{
addr_len = sizeof(s1_addr);
rval=recvfrom(sockfd,buff,sizeof(buff),0,(struct sockaddr *)&s1_addr,&addr_len);
if (rval == -1)
{
printf("While receving problem");
close(sockfd);
}
else
{
puts("from server received ");
puts(buff);
}
read(0,buff,sizeof(buff));
rval = sendto(sockfd, buff, sizeof(buff), 0, (struct sockaddr *)&s1_addr,sizeof(s1_addr) );
if (rval == -1)
{
printf("While sending problem");
close(sockfd);
}
} // while end
close(sockfd);
}
CLIENT2
#include “stdio.h “
#include “sys/types.h “
#include “sys/socket.h “
#include “netinet/in.h “
#include “string.h “
#define MAXSIZE 25
main()
{
system("clear");
struct sockaddr_in c_addr, s1_addr;
int sockfd, rval;
socklen_t addr_len;
char buff[MAXSIZE];
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == -1)
printf("Error while socket creation");
s1_addr.sin_family = AF_INET;
s1_addr.sin_port = htons(6919);
s1_addr.sin_addr.s_addr = inet_addr("127.0.0.1") ;
read(0,buff,sizeof(buff));
rval=sendto(sockfd,buff,sizeof(buff),0,(struct sockaddr *)&s1_addr ,sizeof(s1_addr));
if (rval==-1)
{
printf("While sending problem");
close(sockfd);
}
while(1)
{
read(0,buff,sizeof(buff));
rval=sendto(sockfd,buff,sizeof(buff),0,(struct sockaddr *)&s1_addr,sizeof(s1_addr) );
if (rval == -1)
{
printf("While sending problem");
close(sockfd);
}
addr_len = sizeof(s1_addr);
rval = recvfrom(sockfd,buff,sizeof(buff),0,(struct sockaddr *)&s1_addr,&addr_len );
if (rval == -1)
{
printf("While receving problem");
close(sockfd);
}
else
{
puts("from server received ");
puts(buff);
}
} // while end
close(sockfd);
}
OUTPUT
SERVER
[NPLab@localhost ~]$ cc multis.c
[NPLab@localhost ~]$ ./a.out
hi
hello
CLIENT1
[NPLab@localhost ~]$ cc multic1.c
[NPLab@localhost ~]$ ./a.out
hi
CLIENT2
[NPLab@localhost ~]$ cc multic2.c
[NPLab@localhost ~]$ ./a.out
hello
SLIDING WINDOW PROTOCOL
SOURCE CODE
SERVER
#include “stdio.h “
#include “sys/types.h “
#include “sys/socket.h “
#include “netinet/in.h “
#include “arpa/inet.h “
#include “string.h “
#include “stdlib.h “
#include “arpa/inet.h “
#include “unistd.h “
#define SIZE 4
main()
{
int id,lfd,i,j,status,n;
char str[20],frame[20],temp[20],ack[20];
socklen_t len;
struct sockaddr_in server,client;
id=socket(AF_INET,SOCK_STREAM,0);
if(id < sin_family="AF_INET;" sin_port="htons(8565);" s_addr="htonl(INADDR_ANY);" len="sizeof(&client);" lfd="accept(id,(struct" i="0;" n="strlen(frame);" j="0;j" status="="-1)" j="0;;)" 4="="0)" n="strlen(frame);" j="0;j" id="socket(AF_INET,SOCK_STREAM,0))="="-1)" sin_family="AF_INET;" sin_port="htons(8565);" c="connect(id,(struct"> y 0-- > n)",str);
scanf("%d",&choice);
if(!choice)
write(id,"-1",sizeof("-1"));
else
{
printf("Enter The Sequence Of Frame Where Error Has Occured: ");
scanf("%s",err);
write(id,err,sizeof(err));
read(id,str,20);
printf("\n\n Received The Retransmitted Frames %s\n\n",str);
}
}
close(id);
return 0;
}
OUTPUT:
SERVER:
[NPLab@localhost ~]$ cc slides21.c
[NPLab@localhost ~]$ ./a.out
Enter The Text: HELLO
Transmitting Frames
0123
Transmission Is Successful
Transmitting Frames
4
Transmission Is Successful
EXITING
CLIENT:
[NPLab@localhost ~]$ cc slidec21.c
[NPLab@localhost ~]$ ./a.out
Received HELL0123
Want To Report An Error? (1-- > y 0-- > n)0
Received O4
Want To Report An Error? (1-- > y 0-- > n)0
EXITING
UDP CHAT
SOURCE CODE
SERVER
#include “stdio.h “
#include “netinet/in.h “
#include “stdlib.h “
#include “fcntl.h “
#include “unistd.h “
#include “sys/socket.h “
main()
{
char buf[512]={" "};
int s,id,r,b;
socklen_t n;
struct sockaddr_in server,client;
id=socket(AF_INET,SOCK_DGRAM,0);
if(id < sin_family="AF_INET;" sin_port="htons(6789);" s_addr="inet_addr(" n="sizeof(server);" b="bind(id,(const" n="sizeof(client);" r="recvfrom(id,(void" s="sendto(id,(void">
#include “stdio.h “
#include “unistd.h “
#include “stdlib.h “
#include “sys/socket.h “
#include “fcntl.h “
#include “netinet/in.h “
main()
{
char buf[512]={""};
int id,s,b,r;
struct sockaddr_in server,client;
socklen_t n;
id=socket(AF_INET,SOCK_DGRAM,0);
if(id < sin_family="AF_INET;" sin_port="htons(6789);" s_addr="inet_addr(" sin_family="AF_INET;" s_addr="inet_addr(" sin_port="htons(6789);" s="sendto(id,(void" n="sizeof(server);" r="recvfrom(id,(void" color="#000099">OUTPUT
SERVER
[NPLab@localhost ~]$ cc udpchatser21.c
[NPLab@localhost ~]$ ./a.out
hi
Enter The Data: hello
end
o
Enter The Data: end
[NPLab@localhost ~]$
CLIENT
[NPLab@localhost ~]$ cc udpchat21.c
[NPLab@localhost ~]$ ./a.out
Enter The Data:hi
hello
Enter The Data:end
[NPLab@localhost ~]$
UDP SOCKET
UDP SERVER:
#include “stdio.h “
#include “netinet/in.h “
#include “stdio.h “
#include “sys/types.h “
#include “errno.h “
#include “sys/socket.h “
#define MAX 100
#define PORT 8080
int main()
{
char buf[MAX]={" "};
int i,id,t,b,l,n;
socklen_t ct;
struct sockaddr_in server,client;
id=socket(AF_INET,SOCK_DGRAM,0);
if(id < 0)
{
write(1,"socket error",17);
_Exit(1);
}
server.sin_family=AF_INET;
server.sin_port=htons(PORT);
server.sin_addr.s_addr=inet_addr("170.100.40.180");
b=bind(id,(struct sockaddr *)&server,sizeof(server));
if(b < 0)
{
write(1,"bind error",10);
_Exit(0);
}
while(1)
{
ct=sizeof(client);
n=recvfrom(id,buf,sizeof(buf),0,(struct sockaddr *)&client,&ct);
if(n < 0)
{
write(1,"receive error",13);
_Exit(0);
}
if(strcmp(buf,"end",2)==0)
{
_Exit(0);
}
printf("\nMESSAGE FROM CLIENT: %s",buf);
printf("\nCLIENT PORT NUMBER: %d",ntohs(client.sin_port));
printf("CLIENT IP ADDRESS: %s",inet_ntoa(client.sin_addr));
}
return 0;
}
UDP CLIENT:
#include “stdio.h “
#include “unistd.h “
#include “sys/types.h “
#include “sys/socket.h “
#include “errno.h “
#include “fcntl.h “
#include “netinet/in.h “
#define MAX 100
#define PORT 8080
int main()
{
char buf[MAX]={""};
int i,sd,t,b,l,ct,n;
struct sockaddr_in server,client;
socklen_t len;
sd=socket(AF_INET,SOCK_DGRAM,0);
if(sd < 0)
{
write(1,"Socket error",17);
_exit(1);
}
client.sin_family=AF_INET;
client.sin_port=htons(PORT);
client.sin_addr.s_addr=inet_addr("170.100.40.25");
server.sin_family=AF_INET;
server.sin_addr.s_addr=inet_addr("170.100.40.180");
server.sin_port=htons((short)8080);
while(1)
{
write(1,"Enter The Data: ",17);
n=read(0,buf,MAX);
len=sizeof(server);
l=sendto(sd,buf,n,0,(struct sockaddr *)&server,len);
if(strcmp(buf,"end",23)==0)
{
_exit(1);
}
if(l < 0)
{
printf("Error Sending");
_exit(0);
}
}
return 0;
}
OUTPUT:
SERVER:
[NPLab@localhost ~]$ cc udpserver21.c
[NPLab@localhost ~]$ ./a.out
MESSAGE FROM CLIENT: hi
CLIENT PORT NUMBER: 32822
CLIENT IP ADDRESS: 170.100.40.180
MESSAGE FROM CLIENT: hello
CLIENT PORT NUMBER: 32822
CLIENT IP ADDRESS: 170.100.40.180
CLIENT:
[NPLab@localhost ~]$ cc udpclient21.c
[NPLab@localhost ~]$ ./a.out
Enter The Data: hi
Enter The Data: hello
Enter The Data: end
[NPLab@localhost ~]$
TCP SOCKETS
TCP CLIENT
#include “sys/socket.h “
#include “unistd.h “
#include “fcntl.h “
#include “netdb.h “
int main()
{
char buff[512]={""};
int id,b,c,s,a,r,n,l;
int len;
struct sockaddr_in client,server;
id=socket(AF_INET,SOCK_STREAM,0);
if(id < sin_family="AF_INET;" sin_port="8080;" s_addr="inet_addr(" sin_family="AF_INET;" sin_port="8080;" s_addr="inet_addr(" len="sizeof(server);" c="connect(id,(struct" s="send(id,&buff,sizeof(buff),0);" n="read(id,buff,sizeof(buff));">
TCP SERVER:
#include “sys/socket.h “
#include “stdio.h “
#include “unistd.h “
#include “fcntl.h “
#include “netinet/in.h “
main()
{
char buff[512]={""},buf[512]={""};
int id,a,b,l,r,s;
socklen_t n;
struct sockaddr_in server,client;
id=socket(AF_INET,SOCK_STREAM,0);
if(id < sin_family="AF_INET;" sin_port="8080;" s_addr="inet_addr(" b="bind(id,(struct" l="listen(id,1);" n="sizeof(client);" a="accept(id,(struct" r="read(a,buff,sizeof(buff));" ndata="%s" color="#000099">
OUTPUT:
TCP SERVER:
[NPLab@localhost ~]$ cc tcpserver.c
[NPLab@localhost ~]$ ./a.out
hi
PORT NUMBER: 50638
IP ADDRESS: 170.100.40.180
DATA=hi
[NPLab@localhost ~]$
TCP CLIENT:
[NPLab@localhost ~]$ ./a.out
Enter The Data
hi
msg sent
[NPLab@localhost ~]$
TCP SOCKET - FT
FILE TRANSFER APPLICATION USING TCP SOCKET
SOURCE CODE
SERVER
#include “stdio.h “
#include “unistd.h “
#include “sys/types.h “
#include “sys/socket.h “
#include “sys/stat.h “
#include “fcntl.h “
#include “netinet/in.h “
main()
{
char buf[512]={""},buff[512]={""};
int id,b,a,r,i,l,s,f1,x;
socklen_t n;
struct stat a1;
struct sockaddr_in server,client;
id=socket(AF_INET,SOCK_STREAM,0);
if(id < sin_family="AF_INET;" sin_port="htons(8483);" s_addr="INADDR_ANY;" b="bind(id,(struct" l="listen(id,1);" n="sizeof(client);" a="accept(id,(struct" r="read(a,buff,sizeof(buff));"> 0)
{
write(1,"file does not exist",32);
_exit(0);
}
stat(buff,&a1);
if(!S_ISREG(a1.st_mode))
{
write(1,"\nfile is not a regular file",28);
_exit(0);
}
if((f1=open(buff,0))==-1)
{
write(1,"cannot open the file",20);
_exit(0);
}
while((n=read(f1,buf,512)) > 0)
{
if(write(a,buf,n)==-1)
{
write(1,"write error",12);
_exit(0);
}
}
write(1,buf,sizeof(buf));
printf("PORT NUMBER: %u",client.sin_port);
printf("IP ADDRESS: %s",inet_ntoa(client.sin_addr));
write(a,"DATA RECEIVED",14);
write(a,"\n",2);
close(id);
}
CLIENT:
#include “unistd.h “
#include “stdio.h “
#include “sys/socket.h “
#include “sys/types.h “
#include “sys/stat.h “
#include “fcntl.h “
#include “netinet/in.h “
main()
{
char buf[512]={""},buff[512]={""};
int id,b,c,s,a,r,n,l;
struct stat a1;
struct sockaddr_in server,client;
id=socket(AF_INET,SOCK_STREAM,0);
if(id < sin_family="AF_INET;" sin_port="htons(8483);" s_addr="INADDR_ANY;" sin_family="AF_INET;" sin_port="htons(8483);" s_addr="INADDR_ANY;" c="connect(id,(struct" s="send(id,&buff,sizeof(buff),0);">
Output
SERVER:
[NPLab@localhost ~]$ cc fts.c
[NPLab@localhost ~]$ ./a.out
apple
orange
mango
grapes
pineapple
[NPLab@localhost ~]$
CLIENT:
[NPLab@localhost ~]$ cc ftc.c
[NPLab@localhost ~]$ ./a.out
Enter The File To Transfer:fruits.txt
apple
orange
mango
grapes
pineapple
[NPLab@localhost ~]$
Domain Name Services
SOURCE CODE
#include “stdio.h “
#include “netdb.h” /* This is the header file needed for gethostbyname () */
#include “sys/types.h”
#include “sys/socket.h”
#include “netinet/in.h”
#include “stdlib.h”
int main(int argc, char *argv[])
{
struct hostent *he;
if (argc!=2)
{
printf ("Usage: %s <>\n", argv[0]);
exit (-1);
}
if ((he=gethostbyname (argv[1]))==NULL)
{
printf ("gethostbyname() error\n");
exit (-1);
}
printf ("Hostname : %s\n", he->h_name); /* prints the hostname */
printf ("IP Address: %s\n",inet_ntoa(*((struct in_addr *)he->h_addr)));
}
OUTPUT:
[NPLab@localhost ~]$ cc dns21.c
[NPLab@localhost ~]$ ./a.out sys26.server1.com
Hostname : sys26.server1.com
IP Address: 170.100.140.125
Remote Procedure Call
REMOTE PROCEDURE CALL
ADD.X
struct add_arg
{
int first;
int second;
};
program ADDPROG {
version ADDVER {
int add(add_arg)=1;
}=1;
}=0x20000199;
ADDCLIENT21.C
#include “ stdio.h “
#include “ ctype.h “
#include “ rpc/rpc.h “
#include "add.h"
add_arg arg;
main(argc,argv)
int argc;
char *argv[];
{
CLIENT *clnt;
int *result;
if(argc!=4)
{
printf("USAGE= %s HOST NUM1 NUM2 \n",argv[0]);
exit(1);
}
clnt=clnt_create(argv[1],ADDPROG,ADDVER,"udp");
if(clnt==NULL)
{
clnt_pcreateerror(argv[1]);
exit(1);
}
arg.first=atoi(argv[2]);
arg.second=atoi(argv[3]);
result=add_1(&arg,clnt);
if(result==(int *)NULL)
{
clnt_perror(clnt,"call failed");
exit(1);
}
else
{
printf("SUCCESS: %d + %d = %d\n",arg.first,arg.second,*result);
}
exit(0);
}
ADDSERVER21.C
#include "add.h"
int *add_1_svc(argp,rqstp)
add_arg *argp;
struct svc_req *rqstp;
{
static int result;
result=argp- > first+argp- > second;
return(&result);
}
OUTPUT
[NPLab@localhost rpc]$ ls
addclient21.c addserver21.c add.x
[NPLab@localhost rpc]$ rpcgen add.x
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c add.h addserver21.c add_svc.c add.x add_xdr.c
[NPLab@localhost rpc]$ cc -c addclient21.c
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c addserver21.c add.x
addclient21.o add.h add_svc.c add_xdr.c
[NPLab@localhost rpc]$ cc -c add_clnt.c
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c add.h add_svc.c add_xdr.c
addclient21.o add_clnt.o addserver21.c add.x
[NPLab@localhost rpc]$ cc -c add_xdr.c
[NPLab@localhost rpc]$ ls
addclient21.c add_clnt.c add.h add_svc.c add_xdr.c
addclient21.o add_clnt.o addserver21.c add.x add_xdr.o
[NPLab@localhost rpc]$ cc -o addc21 addclient21.o add_clnt.o add_xdr.c
[NPLab@localhost rpc]$ ls
addc21 addclient21.o add_clnt.o addserver21.c add.x add_xdr.o addclient21.c add_clnt.c add.h add_svc.c add_xdr.c
[NPLab@localhost rpc]$ cc -c addserver21.c
[NPLab@localhost rpc]$ ls
addc21 addclient21.o add_clnt.o addserver21.c add_svc.c add_xdr.c addclient21.c add_clnt.c add.h add.x addserver21.o add_xdr.o
[NPLab@localhost rpc]$ cc -c add_svc.c
[NPLab@localhost rpc]$ ls
addc21 add_clnt.c addserver21.c add_svc.o add_xdr.o
addclient21.c add_clnt.o addserver21.o add.x addclient21.o add.h add_svc.c add_xdr.c
[NPLab@localhost rpc]$ cc -o adds21 addserver21.o add_svc.o add_xdr.c
[NPLab@localhost rpc]$ ls
addc21 add_clnt.c adds21 add_svc.c add_xdr.c
addclient21.c add_clnt.o addserver21.c add_svc.o add_xdr.o addclient21.o add.h addserver21.o add.x
SERVER:
[NPLab@localhost ~]$ ./adds21
CLIENT:
[NPLab@localhost ~]$ ./addc21 localhost 3 7
SUCCESS: 3 + 7 = 10
ROUTING PROTOCOLS
#include” stdio.h”
#include “ ctype.h “
int graph[12][12];
int e[12][12];
int ad[12];
int no,id,adc,small,chosen;
char nodes[12]={"abcdefghijkl"};
int main()
{
int i,j,k,ch1,ch2=0;
adc=0;
printf("Enter no of nodes:");
scanf("%d",&no);
printf("\n Enter the values for adjacency matrix:");
for(i=0;i < j="0;j" i="0;i" j="0;j" adc="0;" i="0;i" i="0;i" small="100;" chosen="1;" j="0;j" total="e[ad[j]][i]+e[id][ad[j]];" small="total;" chosen="j;" i="0;i" j="0;j" ch2="="1);">
Inventory program
Use Case Diagram


Collabration Diagram

Component Diagram

Deployment Diagram

Screen Desing in VB6.0
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
If con.State = 1 Then con.Close
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=stk")
rs.Open "select*from slogin", con, adOpenDynamic, adLockOptimistic
con.Execute ("insert into slogin values('" & Text1.Text & "','" & Text2.Text & "')")
MsgBox ("")
End Sub
Private Sub Form_Load()
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=stk")
rs.Open "select * from slogin", con, adOpenDynamic, adLockOptimistic
Frame1.Visible = False
userADD.Visible = False
End Sub
Private Sub Label1_Click()
PurchaseFrm.Show
Unload Me
End Sub
Private Sub Label2_Click()
SalesFrm.Show
Unload Me
End Sub
Private Sub Label3_Click()
DataReport1.Show
End Sub
Private Sub OKButt_Click()
rs.MoveFirst
Do While Not rs.EOF
If Text1.Text = rs.Fields("uname") And Text2.Text = rs.Fields("passwd") Then
MsgBox "Congratulations"
Frame1.Visible = True
Frame2.Visible = False
Else
MsgBox "Please Enter the Correct Username and Password"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
rs.MoveNext
Loop
End Sub
Screen Design

SOURCE CODE
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rsstk As New ADODB.Recordset
Private Sub AddButt_Click()
If con.State = 1 Then con.Close
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=stk")
rsstk.Open "select*from stkview", con, adOpenDynamic, adLockOptimistic
rs.Open "select*from purch", con, adOpenDynamic, adLockOptimistic
con.Execute ("insert into purch values(" & Text1.Text & ",'" & Text2.Text & "','" & Text3.Text & "','" & Combo1.Text & "'," & Text4.Text & "," & Text5.Text & "," & Text6.Text & ")")
MsgBox ("Stored your Purchase Details")
Dim N As Integer
N = Val(Text7)
con.Execute ("update stkview set pname='" & Combo1.Text & "',pqty=" & Text8.Text & " where pid=" & N & " ")
MsgBox ("Stock Also Updated")
Call TextClear
End Sub
Private Sub Combo1_Click()
rsstk.MoveFirst
Do While Not rsstk.EOF
If rsstk.Fields("pname") = Combo1.Text Then
Text7.Text = rsstk.Fields("pid")
Text8.Text = rsstk.Fields("pqty")
End If
rsstk.MoveNext
Loop
End Sub
Private Sub Form_Load()
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=stk")
rs.Open "select * from purch", con, adOpenDynamic, adLockOptimistic
rsstk.Open "select * from stkview", con, adOpenDynamic, adLockOptimistic
Combo1.Clear
rsstk.MoveFirst
Do While Not rsstk.EOF
Combo1.AddItem (rsstk.Fields("pname"))
rsstk.MoveNext
Loop
Text7.Visible = False
Text8.Visible = False
End Sub
Private Sub Text5_LostFocus()
Text6 = Val(Text4) * Val(Text5)
Text8 = Val(Text8) + Val(Text5)
End Sub
Public Sub TextClear()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
End Sub
Screen Design
Dim rs As New ADODB.Recordset
Dim rsstk As New ADODB.Recordset
Private Sub AddButt_Click()
If con.State = 1 Then con.Close
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=stk")
rsstk.Open "select*from stkview", con, adOpenDynamic, adLockOptimistic
rs.Open "select*from sales", con, adOpenDynamic, adLockOptimistic
con.Execute ("insert into sales values(" & Text1.Text & ",'" & Text2.Text & "','" & Text3.Text & "','" & Combo1.Text & "'," & Text4.Text & "," & Text5.Text & "," & Text6.Text & ")")
MsgBox ("Stored your Sales Details")
Dim N As Integer
N = Val(Text7)
con.Execute ("update stkview set pname='" & Combo1.Text & "',pqty=" & Text8.Text & " where pid=" & N & " ")
MsgBox ("Stock Also Updated")
End Sub
Private Sub Combo1_Click()
rsstk.MoveFirst
Do While Not rsstk.EOF
If rsstk.Fields("pname") = Combo1.Text Then
Text7.Text = rsstk.Fields("pid")
Text8.Text = rsstk.Fields("pqty")
End If
rsstk.MoveNext
Loop
If Combo1.Text = "MOUSE" Then
Text4.Text = 75
ElseIf Combo1.Text = "KEYBOARD" Then
Text4.Text = 115
ElseIf Combo1.Text = "MONITOR" Then
Text4.Text = 4500
End If
End Sub
Private Sub Form_Load()
con.Open ("Provide=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=stk")
rsstk.Open "select * from stkview", con, adOpenDynamic, adLockOptimistic
Cmbo1.Clear
rsstk.MoveFirst
Do While Not rsstk.EOF
Combo1.AddItem (rsstk.Fields("pname"))
rsstk.MoveNext
Loop
Text7.Visible = False
Text8.Visible = False
End Sub
Private Sub Text5_LostFocus()
Text6 = Val(Text4) * Val(Text5)
Text8 = Val(Text8) - Val(Text5)
End Sub
After Purchase and Sales - Stock Details
ONLINE RAILWAY RESERVATION SYSTEM
USE CASE DIAGRAM

Create following Table in ORACLE


New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=railway")
rs.Open "select * from rrlogin", con, adOpenDynamic, adLockOptimistic
Frame1.Visible = True
Frame2.Visible = False
End Sub
Private Sub LoginButt_Click()
rs.MoveFirst
Do While Not rs.EOF
If Val(Text5) = rs.Fields("id") And Text1.Text = rs.Fields("username") And Text2.Text = rs.Fields("password") Then
MsgBox " Congratulation"
Form2.Show
Else
End If
rs.MoveNext
Loop
End Sub
Private Sub NewUserButt_Click()
Frame2.Visible = True
Frame1.Visible = False
End Sub
Private Sub SubmitButt_Click()
If con.State = 1 Then con.Close
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=railway")
con.Execute ("insert into rrlogin values(" & Text6.Text & ",'" & Text3.Text & "','" & Text4.Text & "')")
MsgBox ("Login Created Successfully")
Text3 = ""
Text4 = ""
Frame2.Visible = False
Frame1.Visible = True
End Sub
Private Sub Text5_LostFocus()
rs.MoveFirst
Do While Not rs.EOF
If rs.Fields("id") = Val(Text5) Then
Text1.Text = rs.Fields("username")
End If
rs.MoveNext
Loop
End Sub
Screen Design
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
If con.State = 1 Then con.Close
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=railway")
con.Execute ("insert into tdetails values(" & Combo1.Text & ",'" & Text1.Text & "','" & Text2.Text & "','" & Text3.Text & "','" & Text4.Text & "')")
MsgBox (" Successfully")
End Sub
Private Sub Command2_Click()
Form3.Show
End Sub
Private Sub DISP_BUTT_Click()
rs.MoveFirst
Do While Not rs.EOF
If rs.Fields(0) = Combo1.Text Then
Text1.Text = rs.Fields(1)
Text2.Text = rs.Fields(2)
Text3.Text = rs.Fields(3)
Text4.Text = rs.Fields(4)
End If
rs.MoveNext
Loop
Command2.Visible = True
End Sub
Private Sub Form_Load()
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=railway")
rs.Open "select * from tdetails", con, adOpenDynamic, adLockOptimistic
Command2.Visible = False
Command1.Visible = False
Combo1.AddItem ("2601")
Combo1.AddItem ("2602")
Combo1.AddItem ("2651")
Combo1.AddItem ("2652")
Combo1.AddItem ("2221")
Combo1.AddItem ("2222")
Combo1.AddItem ("2631")
Combo1.AddItem ("2632")
End Sub
Screen Design

Source Code
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Private Sub Combo1_Click()
rs1.MoveFirst
Do While Not rs1.EOF
If rs1.Fields(0) = Combo1.Text Then
Text1.Text = rs1.Fields(1)
Text2.Text = rs1.Fields(2)
Text3.Text = rs1.Fields(3)
Text4.Text = rs1.Fields(4)
End If
rs1.MoveNext
Loop
End Sub
Private Sub Form_Load()
con.Open ("Provider=MSDASQL.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=railway")
rs.Open "select * from booking", con, adOpenDynamic, adLockOptimistic
rs1.Open "select * from tdetails", con, adOpenDynamic, adLockOptimistic
Combo1.Clear
rs1.MoveFirst
Do While Not rs1.EOF
Combo1.AddItem (rs1.Fields(0))
rs1.MoveNext
Loop
Text6.Visible = False
End Sub
WINSOCK CONTROL - Client -Chat
Client.cpp
#include ” stdio.h “
#include “ winsock.h “
void main()
{
WSADATA wsaData;
char buf1[256];
int iResult = WSAStartup(0x101,&wsaData);
SOCKET m_socket;
m_socket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(m_socket == -1)
{
printf("Error in Socket Creation\n");
closesocket(m_socket);
return;
}
else
{
printf("Socket Successfully Created\n");
}
sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_addr.S_un.S_addr = inet_addr("170.100.40.83");
saddr.sin_port = htons(8101);
printf("Initilised\n");
if(connect(m_socket,(SOCKADDR*)&saddr,sizeof(saddr)) == -1)
{
printf("Error in Connection\n");
WSACleanup();
return;
}
printf("Connected Successfully\n");
memset(buf1,0,256);
printf("Enter your Message\n");
scanf("%s",buf1);
while(1)
{
send(m_socket,buf1,256,0);
memset(buf1,0,256);
if(recv(m_socket,buf1,256,0) > 0)
{
printf("Message From Server\t%s\n",buf1);
printf("Enter ur Message");
scanf("%s",buf1);
}
}
closesocket(m_socket);
}
OUTPUT
