Your IP : 216.73.216.40


Current Path : /var/www/html/vijayk/p2p/
Upload File :
Current File : /var/www/html/vijayk/p2p/DGRAM_new_server.c

#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<string.h>
#include<sys/stat.h>
#include<fcntl.h>

int main(){
	int s,k;
	int n=32;
	char buf[20];
	//const char *ch;
	char ch[100];
	bzero(ch,100);
	
	FILE *fin;
	socklen_t len=sizeof(struct sockaddr_in);
	struct sockaddr_in sadd,cadd;
	

	
	
	s=socket(AF_INET,SOCK_DGRAM,0);
	if(s>0)
	printf("Socket Created\n");	
	
	
	bzero(&sadd, sizeof(sadd));
	sadd.sin_family=AF_INET;
	sadd.sin_addr.s_addr=INADDR_ANY;
	sadd.sin_port=htons(6202);	

	k=bind(s, (struct sockaddr *)&sadd, sizeof(sadd));
	if(k==0)
	printf("Bind Successful\n",n);	
	fflush(stdout);
	

		
	recvfrom(s,buf,20,0,(struct sockaddr*)&cadd,&len);
	printf("sending file : %s\n", buf);
	
	fin=fopen("data.txt", "r");
	
	
	while(n==32)
		{
		n=fread(ch,1,32,fin);
		printf("%d",n);	
		sendto(s,&ch,n,0,(struct sockaddr*)&cadd,len );
		printf("%s", ch);
		}
	
	fclose(fin);
	close(s);
}