Network Programming - Programs

Page 1 2 3 4 5 6 7 8 9

MULTI USER CHAT


SLIDING WINDOW PROTOCOL


UDP CHAT


UDP SOCKET


TCP SOCKETS


TCP SOCKET - FT


Domain Name Services


Remote Procedure Call


ROUTING PROTOCOLS

Page : 1 2 3 4 5 6 7 8 9

MULTI USER CHAT


Page 1 2 3 4 5 6 7 8 9



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


Page 1 2 3 4 5 6 7 8 9



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

Page 1 2 3 4 5 6 7 8 9

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

Page 1 2 3 4 5 6 7 8 9
SOURCE CODE:

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

Page 1 2 3 4 5 6 7 8 9
SOURCE CODE

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

Page 1 2 3 4 5 6 7 8 9


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

Page 1 2 3 4 5 6 7 8 9


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


Page 1 2 3 4 5 6 7 8 9

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

Page 1 2 3 4 5 6 7 8 9
ROUTING PROTOCOLS-DVR ROUTING ALGORITHM


#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);">

BUSINESS PLANNING PROCESS


Page: 1 2 3 4 5 6 7 8 9



Use Case Diagram

Class Diagram

Sequence Diagram for Customer
Sequence Diagram for Server
Collaboration Diagram for Customer
Collaboration diagram for Server
Analysis


Inventory program


Page: 1 2 3 4 5 6 7 8 9




Use Case Diagram




Activity Diagram



Collabration Diagram


Component Diagram





Deployment Diagram


Screen Desing in VB6.0

SOURCE CODE

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

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 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


Page: 1 2 3 4 5 6 7 8 9


USE CASE DIAGRAM
CLASS DIAGRAM




TABLES

Create following Table in ORACLE








Open VB6.0 and Design the Screen and write the following Surce Code


Screen Design
Source Code

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

Source Code
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=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()
' Data retrive from tdetails Table

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


Win32 Application

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




WINSOCK CONTROL - Server - Chat

Win32 Application

Server.cpp


#include " stdio.h "
#include " winsock.h "
void main()
{
WSADATA wsaData;
int aid;
char buf2[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 Connection\n");
closesocket(m_socket);
return;
}
else
{
printf("Socket Created Successfully\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("Initialised\n");
if(bind(m_socket,(SOCKADDR*)&saddr,sizeof(saddr)) == -1)
{
printf("Error in Connection\n");
closesocket(m_socket);
return;
}
printf("Binded Successfully\n");
if(listen(m_socket,1) == -1)
printf("Error in Listening\n");
else
printf("Listened\n");
printf("Waiting for a client to connect\n");
while(1)
{
if((aid=accept(m_socket,NULL,NULL)) == -1)
{
printf("Error in accepting client\n");
exit(1);
}
printf("Accepted\n");
printf("Client Connected\n");
memset(buf2,0,256);
while(recv(aid,buf2,256,0) > 0)
{
printf("Message from Client\t%s\n", buf2);
printf("Enter ur Message(Server)");
scanf("%s",buf2);
send(aid,buf2,256,0);
}
}
closesocket(m_socket);
closesocket(aid);
}