LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-31-2008, 11:57 PM   #1
Kakarot_Rathish
Member
 
Registered: Sep 2008
Posts: 35
Blog Entries: 1

Rep: Reputation: 15
Server Client communication


i want to make a server- client program to implement sliding window and Stop and Wait
with both "Go Back -n ARQ" and "Selective Reject ARQ"in the case of sliding window error handling
i just wanted to know if there are protocols for doing these.
i dont know network programming much.this is my first trial.

Last edited by Kakarot_Rathish; 01-02-2009 at 02:07 AM.
 
Old 01-01-2009, 12:27 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
I don't know anything about this subject, but have you tried searching the web for those phrases? I got enough useful-looking material to last me for days if I wanted to look into it.

Sorry for such a lame response, but there's a slight chance it might be helpful.
 
Old 01-01-2009, 07:12 AM   #3
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

Rep: Reputation: 32
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
 
Old 01-02-2009, 02:16 AM   #4
Kakarot_Rathish
Member
 
Registered: Sep 2008
Posts: 35

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Quote:
Originally Posted by pgpython View Post
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
 
Old 01-03-2009, 05:58 PM   #5
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

Rep: Reputation: 32
The program is simple on the client side your creating a tcp/streaming socket to which it connnects to a ip address i.e the server. The server creates a sockets which listens to the same port as the client is sending to and binding itself to a ip adresss it intends to listen to. once it recieves it some data it prints it out then closes the connection. the important thing to realise in tcp is that packets always arrive in the correct order and because the two points can be thought of as physically connected if a packet is missing the server will rerequest it. Timeouts are also important as you can wait be forever for a packet which will never arrive. In UDP this isn't the case. If you want to use udp sock you use SOCK_DATAGRAM instead of SOCK_STREAM and you will also to change the commands tou use to send and recieve
 
Old 01-09-2009, 04:42 AM   #6
Kakarot_Rathish
Member
 
Registered: Sep 2008
Posts: 35

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Quote:
Originally Posted by pgpython View Post
The program is simple on the client side your creating a tcp/streaming socket to which it connnects to a ip address i.e the server. The server creates a sockets which listens to the same port as the client is sending to and binding itself to a ip adresss it intends to listen to. once it recieves it some data it prints it out then closes the connection. the important thing to realise in tcp is that packets always arrive in the correct order and because the two points can be thought of as physically connected if a packet is missing the server will rerequest it. Timeouts are also important as you can wait be forever for a packet which will never arrive. In UDP this isn't the case. If you want to use udp sock you use SOCK_DATAGRAM instead of SOCK_STREAM and you will also to change the commands tou use to send and recieve


I think i got some idea about the protocol,TCP and UDP.I also read about datagram and stream.
But still what bugging me is the concept of frames.Can anyone tell me how the frames are manipulated?
 
Old 01-09-2009, 02:24 PM   #7
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

Rep: Reputation: 32
What you have to appreciate is that networking at a high level is very abstract and doesn't reflect what really happens. In the example given you given. The string sent can be thought of as continous stream as though the 2 points are physically connected together. However at the lowest level thats not how it happens. The string will get turn into binary data and then maybe broken into packets or frames if its too big. At the other end it restitched together and gets turned back into a string. So In answer to your question what is a frame. It depends slightly on how abstract you want to be.

At the very lowest level you can think of your frame as binary data possibly containing instruction, number, data and some parity bits to make sure the frame is not corrupted.

At a higher level you can think of your frame as a string containg a instruction and possibly some data.

Even higher although maybe a bit too high. you can think of your frame as a serialsed object like a float, struct, int or anything else which has data.


How you implement a frame - that again depends not just on the level but on the very architecture of your network. If your running the program on a local network with just one client then you have the advantage that communication is going to be fairly straightforward with minimal delay, corruption, lost frames etc. However if your running the program across the internet between opposite ends of the earth you don't have that luxury..

But once you have answered these questions you then can design a protocol which will be how the server and client handle a frame. Just remeber the server and client need to have the same understanding of what the protocol is and what the responses are if there is one.
 
Old 01-09-2009, 05:40 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Wow, this sounds entirely too complicated. Here's a simple way to look at it:
  • Files can be read sequentially such that each read stops where the last one left off.
  • A pipe is like a file, but it can only be read sequentially; from the point where the last read left off. Data written to it is added to the end, so it's read in the order it's written.
  • A stream socket (e.g. TCP) is like a two-way pipe, where both ends can write to it and read what the other end wrote. Creating a socket connection between two different processes takes some additional work that a pipe doesn't.
  • The "server" end must create an "inactive" socket and bind it to either a local socket (irrelevant here) or a network port. This lets the OS know whom to contact when connection requests arrive.
  • The "client" end must also create an "inactive" socket, which it "activates" by connecting to a location that has a server listening. In the case of networking, this is done by specifying an IP address and port number.
  • The "server" end "activates" a copy of its "inactive" socket (which is listening) by accepting an incoming connection from a client. With this connection, the server is provided the IP address of of the connecting client, in case that's of some use (networking only.)
  • Once both the server and the client each have an "active" socket connecting them to each other, both can write to the descriptor as if it were a normal file (but only to the end of it,) and the opposite end can read the data exactly as it's been written. This is done using underlying "magic" that isn't relevant at this point.
  • Don't worry about UDP and datagrams at this point; they will probably obscure your learning.
Given the above, if you have an interest in C or C++, look at the manual pages (or the info libc sections) of socket, bind, listen, connect, and accept. The tutorial you've chosen has helped a lot of people; cross-reference the manual pages with the tutorial for a better understanding. Better yet, practice with fork and pipe; if you can get it working that way, it's just a matter of the formality of making the connection when you move on to sockets.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Live communication server 2005 client for linux? alem2k5 Linux - Enterprise 9 07-24-2008 12:24 AM
Fault in KDE processes communication: Could not read network communication list Magnus Johansson MEPIS 0 03-30-2008 12:50 PM
Communication btw Nessus Server & Client ravikumarv Programming 5 11-23-2007 11:18 PM
client server communication suing raw socket revanth Linux - Networking 1 03-13-2007 09:52 PM
Flash Communication server kaboom Linux - Software 0 12-10-2003 02:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration