Saturday, 20 October 2012

Accept n numbers through one program send it to the server program check their for prime numbers send only the prime numbers to client-Java Socket program

tcpserver1.java import java.io.*; import java.net.*; class tcpserver1 { public static void main(String args[])throws Exception { ServerSocket ss = new ServerSocket(6856); Socket cs=ss.accept(); BufferedReader br = new BufferedReader(new InputStreamReader(cs.getInputStream())); PrintStream ps = new PrintStream(cs.getOutputStream()); int[] a=new int[15]; int[] b= new int [15]; int k=0,n,i,j,f=0; n=Integer.parseInt(br.readLine()); for(i=0;i<n;i++) a[i]=Integer.parseInt(br.readLine()); for(i=0;i<n;i++) { for(j=2;j<a[i];j++) { if(a[i]%j==0) { f=1; break; } } if(f==0) { if(a[i]!=1) { b[k]=a[i]; k++; } } f=0; } ps.println(k); for(i=0;i<k;i++) ps.println(b[i]); } } tcpclient1.java import...

Communication between two unrelated process using messege queue

MSGQ1.c  #include<stdio.h>#include<sys/msg.h>#include<string.h>#include<stdlib.h>struct msgbuf {long mtype;char mtext[30];}ptr;int main(){int i=0;int id=msgget(52,0666|IPC_CREAT);if(id>=0)printf("Msg Q created sucessfully\n");elseprintf("Not created\n");printf("Enter the msg type:\n");scanf("%ld",&(ptr.mtype));printf("Enter the msg\n");scanf("%s",ptr.mtext);int p=msgsnd(id,&ptr,(sizeof(ptr.mtext)),0);if(p>=0)printf("Msg send sucessfully\n");elseprintf("Msg not send\n");} MSGQ2.C #include<stdio.h>#include<sys/msg.h>struct...

Sunday, 7 October 2012

Udp Client-Server Communication using java

UDP Client import java.io.*;import java.net.*;class udpclient {    public static void main(String args[])throws Exception    {                DatagramSocket cs = new DatagramSocket(2568);        InetAddress ip = InetAddress.getByName("localhost");        byte[] sD = new byte[1024];        byte[] rD = new byte[1024]; String sen;       ...

Tcp client server communication using Java

TCP Client import java.io.*;import java.net.*; class tcpclient {    public static void main(String args[])throws Exception    {        Socket s = new Socket("localhost",6700);        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));        PrintStream ps2 = new PrintStream(s.getOutputStream());        BufferedReader kb = new BufferedReader(new...

Two unrelated programs uses shared memory

First program #include<stdio.h>#include<sys/shm.h>#include<string.h>int main(){int id=shmget(17,50,0666|IPC_CREAT);if(id>=0){printf("\nShared memory created with id:%d\n",id);}char *adr=shmat(id,NULL,0);if(adr>=0)printf("Memory attached\n");printf("Enter a string\n");char str[10];scanf("%s",str);strncpy(adr,str,sizeof(str));} Second program #include<stdio.h>#include<sys/shm.h>#include<string.h>int main(){int id=shmget(17,0,0666|IPC_CREAT);char str[10];if(id>=0){printf("\nShared memory with id:%d\n...

Page 1 of 2712345Next
Twitter Delicious Facebook Digg Stumbleupon Favorites More