Quote:
Originally Posted by pgpython
You need to have a look at socket programming. There are not terribly complicated things to use and are available to use in most popular languages: Java, C, Python etc. Basically you have two main types of networking sockets. TCP and UDP, plus theres unix sockets on unix variants. TCP has much more to it in terms of error handling and making sure the frames come in the correct order but is slower but if you really want to implement your own then UDP is the one as there is no gurantee a packet will arrive or that it will arrive in the right order
|
I have gone throgh Beej's Guide to network programming but not deeply.
There are certain doubts like in the case of sending a frame and receiving a frame,how do we actually implement a frame.
In Stop and Wait only one frame is sent and in the case of Sliding window a collection of frames.
i'm enclosing the program i am trying to study and on which i'm intended to update and implement both ARQs.
#Client.c
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#define SERV_PORT 5000
#define BUFSIZE 100
int main(int argc,char *argv[])
{
int sd;
struct sockaddr_in serv_addr,client_addr;
int addrlen = sizeof(struct sockaddr_in);
if(argc!=3)
{
printf("Usage: ./ser <IP ADDRESS><PORT>\n");
exit(0);
}
bzero(&serv_addr,sizeof(struct sockaddr_in));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port=htons(atoi(argv[2]));
serv_addr.sin_addr.s_addr=inet_addr(argv[1]);
sd=socket(AF_INET,SOCK_STREAM,0);
connect(sd,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr_in));
send(sd,"hello",6,0);
printf("Data sent..\n");
close(sd);
return(0);
}
#Server.c
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#define SERV_PORT 6000
#define BUFSIZE 100
int main(int argc, char *argv[])
{
int sd,new_sd;
struct sockaddr_in serv_addr,client_addr;
int addrlen = sizeof(struct sockaddr_in);
char buf[BUFSIZE]={0};
if(argc!=2)
{
printf("Usage: ./ser <IP ADDRESS>\n");
exit(0);
}
bzero(&serv_addr,sizeof(struct sockaddr_in));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port=htons(SERV_PORT);
serv_addr.sin_addr.s_addr=inet_addr(argv[1]);
sd=socket(AF_INET,SOCK_STREAM,0);
bind(sd,(struct sockaddr*)&serv_addr,sizeof(struct sockaddr_in));
listen(sd,5);
new_sd=accept(sd,(struct sockaddr*)&client_addr,&addrlen);
recv(new_sd,buf,10,0);
printf("from client:%s\n",buf);
close(sd);
return(0);
}
In the above program a string hello is sent and received
So what does this a "frame" represent actually.
I am not getting the stuff in properly.So if you can help me out understand the program,it would be great
thankyou