[LCP]question

subin jose scorpiosubin at hotmail.com
Sat Feb 28 01:22:14 UTC 2004


u can do that using calls write() and read()
but before that socket descriptors are to be created using socket() call and 
binded to the port u want to listen to using bind()call basic algorithm 
needed for both client and server is below
server

For Server
1.	Create a socket descriptor of family internet(AF_INET) and type TCP 
(SOCK_STREAM) using the procedure call socket()
2.	portno to be used is read from the user and converted to networkbyte 
order using htons().
3.	Declare a variable of structure sockaddr_in to store server details and 
initialise the members
4.	Bind the variable with the socket descriptor using the call bind()

5.	Listen for any incoming connections at socket descriptor using call 
listen()
6.	Accept any request for connection using call accept()which returns a new 
socket descriptor for the connection
7.use call write() to write to the connected client
9.	Close the connection using call close()
For Client
1.	Create a socket descriptor of family internet(AF_INET) and type TCP 
(SOCK_STREAM) using the procedure call socket()
2.	portno to be used is read from the user and converted to networkbyte 
order.
3.	Host name is read from the user and is converted to the address using a 
function call gethostbyname()which returns a pointer to astructure of type 
hostent which contains the fields addr for the address and length which 
stores the length of the address.
4.	Declare a variable of structure sockaddr_in to store server details and 
initialise the members using values from the above.
5.	Bind the variable with the socket descriptor using the call bind()
6.	Connect to the server using the call connect()
7.	Read the contents transmitted from server using the call read()
8.	close the connection

for more details goto this link its a beautiful tutorial for beginners

http://www.ecst.csuchico.edu/~beej/guide/net/html/


>From: "mehul radheshyam choube" <mrc_cprog at rediffmail.com>
>Reply-To: linuxcprogramming at lists.linux.org.au
>To: linuxcprogramming at lists.linux.org.au
>CC: "subin jose" <scorpiosubin at hotmail.com>
>Subject: Re: [LCP]question
>Date: 26 Feb 2004 12:23:25 -0000
>
>explain me how will you send a string "hello client" from the
>server to the client program and recieve back a string
>"hello server" from the client.
>
>mehul.
>
>
>On Mon, 23 Feb 2004 subin jose wrote :
> >
> >hi
> >
> >i am a beginner in c network programming and i want to implement the 
>following.
> >
> >i have two systems a server and a client.suppose the server requests some 
>program in the client to be run(any program like simple addition to  system 
>calls to shutdown the system).i want the server to send the program name to 
>client excecute the program there send back whatever is the result to the 
>server.also i am using a stream  socket
> >
> >thank you
> >
> >subin
> >
> >_________________________________________________________________
> >Post Classifieds on MSN classifieds. 
>http://www.sulekha.com/msnclassifieds Buy and Sell on MSN Classifieds.
> >
> >_______________________________________________
> >This is the Linux C Programming List
> >:  http://lists.linux.org.au/listinfo/linuxcprogramming List
>

_________________________________________________________________
INDIA TODAY @ Rs. 5 for 5 years ! 
http://www.indiatoday.com/itoday/intlsubscription/itsubs/it_offer.html 
Subcribe Now ...




More information about the linuxCprogramming mailing list