EmbLogic's Blog

CONNECTING RASPBERRY PI WITH YOUR LAPTOP/HOST MACHINE

In order to connect your Raspberry Pi and laptop, you could do it in two ways,

router based connection.
peer to peer connection.

Router Based Connection

In this type of connection it is assumed that your laptop is already in the network, lets say your ip to be 192.168.1.3 and you machine has ssh support.Now in Raspberry it is important that it has ssh support as well. Connect your raspberry pi into the router using a network cable, your raspberry will now have an ip address that was provided by the dhcp server. our next step is to find out the ip address of raspberry pi. In order to get the ip address of raspberry pi we could type ifconfig and look for “inet addr: x.x.x.x” if your raspberry is connected to a monitor. else if it is headless ( without a monitor) then we could look at the ip table of your router by seeing who is connected to the network. now that we know the ip address we could do the following from host machine

$ ssh pi@192.168.1.3

where 192.168.1.3 is the ip address of Raspberry provided by dhcp server.

Peer To Peer Connection

In a peer to peer based connection the Raspberry and host machine is directly connected to each other using a network cable. In order to do this we need static ip’s at both the ends. so we need to make the following change in /etc/network/interfaces file host machine, (note: dont forget to take a backup of /etc/network/interfaces file)

$sudo vim /etc/network/interfaces

auto eth0
iface eth0 inet static
address 192.168.10.2
netmask 255.255.255.0

add the above shown line to the file.

do the same in Raspberry pi as well but the only difference is that the ip address should be 192.168.10.3, note that the network id 192.168.10 should remain same.

after doing this restart the network service by typing the command or by restarting the machine.

$sudo /etc/init.d/networking restart.

then do a

$ssh pi@192.168.10.3

and now it will ask for password, provide the password. So you are now logged it to raspberry pi via ssh.

 

Source

www.emblogic.com

Posted in ARM Embedded Processors, Project 00: Linux System / Network Administration | Leave a comment

Hands on raspberry pi(Soc)

The Raspberry Pi is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation. The Raspberry Pi is manufactured in two board configurations. The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC), which includes an ARM1176JZF-S 700 MHz processor, VideoCore IV GPU shipped with 512 megabytes of RAM. It does not include a built-in hard disk or solid-state drive, but uses an SD card for booting and persistent storage. The Foundation provides Debian and Arch Linux ARM distributions for download. Tools are available for Python as the main programming language, with support for BBC BASIC (via the RISC OS image or the Brandy Basic clone for Linux), C, Java and Perl.

Specification of Raspberry Pi (Model B)
Target price         : US$ 35
SoC                    : Broadcom BCM2835 (CPU, GPU, DSP, SDRAM, and single USB port)
CPU                    : 700 MHz ARM1176JZF-S core (ARM11 family, ARMv6 instruction set)
GPU                   : Broadcom VideoCore IV @ 250 MHz

OpenGL ES 2.0 (24 GFLOPS)

MPEG-2 and VC-1 (with license), 1080p30 h.264/MPEG-4 AVC high profile decoder and encoder

Memory (SDRAM)    : 512 MB (shared with GPU) as of 15 October 2012
USB 2.0 ports            : 1 (direct from BCM2835 chip) 2 (via the built in integrated 3-port     USB hub)
Video input               : A CSI input connector allows for the connection of a RPF designed     camera module
Video outputs           : Composite RCA (PAL and NTSC), HDMI (rev 1.3 & 1.4), raw             LCD Panels via DSI

14 HDMI resolutions from 640×350 to 1920×1200 plus various                                               PAL and NTSC standards.

Audio outputs           : 3.5 mm jack, HDMI, and, as of revision 2 boards, I²S audio(also potentially for audio input)
Onboard storage       : SD / MMC / SDIO card slot (3.3 V card power support only)
Onboard network     : 10/100 Mbit/s Ethernet (8P8C) USB adapter on the third port of the USB hub
Low-level peripherals: 8 × GPIO, UART, I²C bus, SPI bus with two chip selects, I²S audio +3.3 V, +5 V, ground
Power ratings          : 700 mA (3.5 W)
Power source          : 5 V via MicroUSB or GPIO header
Size                        : 85.60 mm × 56 mm (3.370 in × 2.205 in)
Weight                     : 45 g (1.6 oz)
Operating systems   : Arch Linux ARM, Debian GNU/Linux, Gentoo, Fedora, FreeBSD, NetBSD, Plan 9, Raspbian OS, RISC OS, Slackware Linux, OR your own compiled OS (Toolchain in project 9)

Source

http://en.wikipedia.org/wiki/Raspberry_Pi

www.raspberrypi.org

Posted in ARM Embedded Processors, Project 9: Embedded Linux on ARM | Leave a comment

IPC: Message queue

RCS file: msg.c,v
Working file: msg.c
head: 1.19
branch:
locks: strict
akshat: 1.19
access list:
symbolic names:
keyword substitution: kv
total revisions: 19;    selected revisions: 19
description:
IPC project.
This projectb is client server based project using msg queues.
Server is reading data from 3 clients simultaneously.
Semaphore is still not used for synchronisation.
Lets proceed.
—————————-
revision 1.19    locked by: akshat;
date: 2014/04/02 22:06:23;  author: akshat;  state: Exp;  lines: +6 -6
*** empty log message ***
—————————-
revision 1.18
date: 2014/04/02 21:25:08;  author: akshat;  state: Exp;  lines: +2 -2
semaphore is removed.
now its working better than earlier.
—————————-
revision 1.17
date: 2014/04/02 20:59:21;  author: akshat;  state: Exp;  lines: +3 -9
*** empty log message ***
—————————-
revision 1.16
date: 2014/04/02 19:14:43;  author: akshat;  state: Exp;  lines: +4 -0
Sometimes it works and sometimes it dont.
,
—————————-
revision 1.15
date: 2014/04/02 19:04:52;  author: akshat;  state: Exp;  lines: +0 -6
checking for wrong implementation of some functions.
—————————-
revision 1.14
date: 2014/04/02 19:01:02;  author: akshat;  state: Exp;  lines: +11 -10
in server result found is incorrect.
—————————-
revision 1.13
date: 2014/04/02 17:56:34;  author: akshat;  state: Exp;  lines: +14 -12
checking for errors.
—————————-
revision 1.12
date: 2014/04/02 17:50:06;  author: akshat;  state: Exp;  lines: +5 -5
Now next step is to transmit the result from processing clients back to server.
tryng that.
—————————-
revision 1.11
date: 2014/04/02 17:47:32;  author: akshat;  state: Exp;  lines: +2 -2
Both the semaphores are working.
—————————-
revision 1.10
date: 2014/04/02 17:39:59;  author: akshat;  state: Exp;  lines: +12 -2
This is proper implementation using 2 msg queues.
requesting clients are sending data to server.
server is sending this data to processing cluients using single msg queue.
its working.
—————————-
revision 1.9
date: 2014/04/02 17:22:06;  author: akshat;  state: Exp;  lines: +2 -6
on progress.
—————————-
revision 1.8
date: 2014/04/02 17:13:27;  author: akshat;  state: Exp;  lines: +10 -5
not working properly :(
—————————-
revision 1.7
date: 2014/04/02 16:47:55;  author: akshat;  state: Exp;  lines: +1 -0
Working on sending msgs from server to processing client.
—————————-
revision 1.6
date: 2014/04/02 16:34:43;  author: akshat;  state: Exp;  lines: +0 -6
Semaphore is implemented on requesting clients.
its working now,
Result from server has to be passed to processing clients.
—————————-
revision 1.5
date: 2014/04/02 16:15:19;  author: akshat;  state: Exp;  lines: +6 -5
semaphore implementation done.
checking for correct answers.
—————————-
revision 1.4
date: 2014/04/02 15:48:50;  author: akshat;  state: Exp;  lines: +27 -2
Semaphore is used for passing the results from server to processing clients.
Synchronisation was poor otherwise.
lets see if its working.
—————————-
revision 1.3
date: 2014/04/02 15:24:54;  author: akshat;  state: Exp;  lines: +13 -1
no synchronisation.
checking.
—————————-
revision 1.2
date: 2014/04/02 14:49:24;  author: akshat;  state: Exp;  lines: +1 -1
Now passing the operands to processing clients.
lets see if synchronisation is required or not.
,
—————————-
revision 1.1
date: 2014/04/02 14:48:28;  author: akshat;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Initialising the Message Queue

The msgget() function initializes a new message queue:

int msgget(key_t key, int msgflg)

It can also return the message queue ID (msqid) of the queue corresponding to the key argument. The value passed as the msgflg argument must be an octal integer with settings for the queue’s permissions and control flags.

The following code illustrates the msgget() function.

#include <sys/ipc.h>;
#include <sys/msg.h>; 

... 

key_t key; /* key to be passed to msgget() */
int msgflg /* msgflg to be passed to msgget() */
int msqid; /* return value from msgget() */ 

...
key = ...
msgflg = ...

if ((msqid = msgget(key, msgflg)) == &ndash;1)
  {
    perror("msgget: msgget failed");
    exit(1);
   } else
    (void) fprintf(stderr, &ldquo;msgget succeeded");
...
Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

IPC using MSG QUEUE

head 1.1;
access;
symbols;
locks
arjun:1.1; strict;
comment @ * @;

1.1
date 2014.04.01.15.08.45; author arjun; state Exp;
branches;
next ;

desc
@we are using msg queue in ipc project
@

1.1
log
@Initial revision
@

Posted in Uncategorized | Leave a comment

what is bash ?

Bash is the shell, or command language interpreter, for the GNU operating system. The name is an acronym for the ‘Bourne-Again SHell’, a pun on Stephen Bourne, the author of the direct ancestor of the current Unix shell sh, which appeared in the Seventh Edition Bell Labs Research version of Unix.

Bash is largely compatible with sh and incorporates useful features from the Korn shell ksh and the C shell csh. It is intended to be a conformant implementation of the IEEE POSIX Shell and Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1). It offers functional improvements over sh for both interactive and programming use.

While the GNU operating system provides other shells, including a version of csh, Bash is the default shell. Like other GNU software, Bash is quite portable. It currently runs on nearly every version of Unix and a few other operating systems – independently-supported ports exist for MS-DOS, OS/2, and Windows platforms.

Posted in Uncategorized | Leave a comment

push and pop program implement in stack

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2014.04.01.11.46.19;    author root;    state Exp;
branches;
next    ;

desc
@push and pop in stack .
@

1.1
log
@Initial revision
@
text
@#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int push(void **,int *);
int pop(void **,int *);
void display(void **,int *);
int main()
{
void *astack;
int atop=-1;

int ch;
do
{
printf(“\n1:push”);
printf(“\n2:pop”);
printf(“\n3:display”);
printf(“\n enter the choice”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:push(&astack,&atop);
break;
case 2:pop(&astack,&atop);
break;
case 3:display(&astack,&atop);
break;
default:printf(“\nwrong choice”);
break;

}
}while(ch!=4);
return 0;
}
int push(void **astack,int *atop)
{
static char ch=1;
if(*atop>=MAX-1)
{
printf(“\n overflow”);
return-1;
}
if(*atop==-1)
{
*astack= (char*)malloc(1);
(*atop)++;
*(char*)(*astack+*atop)=ch;
ch++;
return -1;
}
*astack=realloc(*astack,(*atop+2));
(*atop)++;
*(char*)(*astack+*atop)=ch;
ch++;
}
int pop(void **astack,int *atop)
{
if(*atop==-1)
{
printf(“stack underflow\n”);
}
printf(“\n %d element %d delete”,*atop,*(char*)(*astack+*atop));
(*atop)–;

}
void display(void **astack,int *atop)
{
int i=0;
for(i=(*atop);i>=0;i–)
{
printf(“\nstack at %d is %d\n”,i,*(char*)(*astack+i));
}
}
@

Posted in Uncategorized | Leave a comment

Message Queues

Message queue is a circular queue which transfer data by giving a tag,tag is generally the id of the data package to be transfered and it differentiates the data from one another.

Message queuing allows distributed applications to communicate asynchronously by sending messages between the applications.  The messages from the sending application are stored in a queue and are retrieved by the receiving application.  The applications send or receive messages through a queue by sending a request to the message queuing system.  Sending and receiving applications can use the same message queuing system or different ones, allowing the message queuing system to handle the forwarding of the messages from the sender queue to the recipient queue.

Queued messages can be stored at intermediate nodes until the system is ready to forward them to the next node.  At the destination node, the messages are stored in a queue until the receiving application retrieves them from the queue.  Message delivery is guaranteed even if the network or application fails.  This provides for a reliable communication channel between the applications.

The complexity and details of the underlying model (to store and forward messages between different environments) are handled by the message queuing system.  By maintaining this level of abstraction, distributed applications can be developed without the need to worry about the details of how the information is transported.

Because the sending and receiving applications operate independently of one another, the sending application is less dependent on the availability of the remote application, less dependent on the network between them, and less dependent on the computer system on which the receiving application runs.  This leads to a higher level of availability for the participating applications.

Messages and message queue operations can be configured by the applications to operate in specific modes.  For example, a sending application can specify that queued messages should survive system crashes.  As another example, the receiving application can specify a maximum waiting period for a receiving operation from a queue (in case no messages are available yet on the receiving queue).

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

Memory Layout of C Programs

A typical memory representation of C program consists of following sections.

1. Text segment
2. Initialized data segment
3. Uninitialized data segment
4. Stack
5. Heap


A typical memory layout of a running process

1. Text Segment:
A text segment , also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.

As a memory region, a text segment may be placed below the heap or stack in order to prevent heaps and stack overflows from overwriting it.

Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions.

2. Initialized Data Segment:
Initialized data segment, usually called simply the Data Segment. A data segment is a portion of virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.

Note that, data segment is not read-only, since the values of the variables can be altered at run time.

This segment can be further classified into initialized read-only area and initialized read-write area.

For instance the global string defined by char s[] = “hello world” in C and a C statement like int debug=1 outside the main (i.e. global) would be stored in initialized read-write area. And a global C statement like const char* string = “hello world” makes the string literal “hello world” to be stored in initialized read-only area and the character pointer variable string in initialized read-write area.

Ex: static int i = 10 will be stored in data segment and global int i = 10 will also be stored in data segment

3. Uninitialized Data Segment:
Uninitialized data segment, often called the “bss” segment, named after an ancient assembler operator that stood for “block started by symbol.” Data in this segment is initialized by the kernel to arithmetic 0 before the program starts executing

uninitialized data starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code.

For instance a variable declared static int i; would be contained in the BSS segment.
For instance a global variable declared int j; would be contained in the BSS segment.

4. Stack:
The stack area traditionally adjoined the heap area and grew the opposite direction; when the stack pointer met the heap pointer, free memory was exhausted. (With modern large address spaces and virtual memory techniques they may be placed almost anywhere, but they still typically grow opposite directions.)

The stack area contains the program stack, a LIFO structure, typically located in the higher parts of memory. On the standard PC x86 computer architecture it grows toward address zero; on some other architectures it grows the opposite direction. A “stack pointer” register tracks the top of the stack; it is adjusted each time a value is “pushed” onto the stack. The set of values pushed for one function call is termed a “stack frame”; A stack frame consists at minimum of a return address.

Stack, where automatic variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller’s environment, such as some of the machine registers, are saved on the stack. The newly called function then allocates room on the stack for its automatic and temporary variables. This is how recursive functions in C can work. Each time a recursive function calls itself, a new stack frame is used, so one set of variables doesn’t interfere with the variables from another instance of the function.

5. Heap:
Heap is the segment where dynamic memory allocation usually takes place.

The heap area begins at the end of the BSS segment and grows to larger addresses from there.The Heap area is managed by malloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single “heap area” is not required to fulfill the contract of malloc/realloc/free; they may also be implemented using mmap to reserve potentially non-contiguous regions of virtual memory into the process’ virtual address space). The Heap area is shared by all shared libraries and dynamically loaded modules in a process.

Posted in Data Structures with C | Leave a comment

ipc using fifo

RCS file: fifoserver.c,v
3 Working file: fifoserver.c
4 head: 1.4
5 branch:
6 locks: strict
7         root: 1.4
8 access list:
9 symbolic names:
10 keyword substitution: kv
11 total revisions: 4;     selected revisions: 4
12 description:
13 client1 had open the fifo and writes the data and then server had read the data.
14 —————————-
15 revision 1.4    locked by: root;
16 date: 2014/03/29 06:49:06;  author: root;  state: Exp;  lines: +1 -1
17 processing client received the data and no.s are added.
18 —————————-
19 revision 1.3
20 date: 2014/03/28 10:47:55;  author: root;  state: Exp;  lines: +10 -2
21 data is read by server from three requesting clients
22 —————————-
23 revision 1.2
24 date: 2014/03/28 09:46:01;  author: root;  state: Exp;  lines: +20 -2
25 data is read in server from two requesting clients
26 —————————-
27 revision 1.1
28 date: 2014/03/28 06:18:35;  author: root;  state: Exp;
29 Initial revision
30 =============================================================================

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

Difference between physical addressing and virtual addressing concept

up vote 8 down vote accepted

Physical addressing means that your program actually knows the real layout of RAM. When you access a variable at address 0x8746b3, that’s where it’s really stored in the physical RAM chips.

With virtual addressing, all application memory accesses go to a page table, which then maps from the virtual to the physical address. So every application has its own “private” address space, and no program can read or write to another program’s memory. This is called segmentation.

Virtual addressing has many benefits. It protects programs from crashing each other through poor pointer manipulation, etc. Because each program has its own distinct virtual memory set, no program can read another’s data – this is both a safety and a security plus. Virtual memory also enables paging, where a program’s physical RAM may be stored on a disk (or, now, slower flash) when not in use, then called back when an application attempts to access the page. Also, since only one program may be resident at a particular physical page, in a physical paging system, either a) all programs must be compiled to load at different memory addresses or b) every program must use Position-Independent Code, or c) some sets of programs cannot run simultaneously.

The physical-virtual mapping may be done in software (with hardware support for memory traps) or in pure hardware. Sometimes even the page tables themselves are on a special set of hardware memory. I don’t know off the top of my head which embedded system does what, but every desktop has a hardware TLB (Translation Lookaside Buffer, basically a cache for the virtual-physical mappings) and some now have advanced Memory Mapping Units that help with virtual machines and the like.

The only downsides of virtual memory are added complexity in the hardware implementation and slower performance.

Posted in Uncategorized | Leave a comment

USE OF SOCKETS

SIMPLE USES OF SOCKET PROGRAMMING IN EMBEDDED SYSTEMS LINUX WITH ‘C’

Typically two processes communicate with each other on a single system through one of the following inter process communication techniques.

  • Pipes
  • Message queues
  • Shared memory

There are several other methods. But the above are some of the very classic ways of interprocess communication.

But have you ever given a thought over how two processes communicate across a network?

For example, when you browse a website, on your local system the process running is your web browser, while on the remote system the process running is the web server. So this is also an inter process communication but the technique through which they communicate with each other is SOCKETS, which is the focus of this article.

What is a SOCKET?

In layman’s term, a Socket is an end point of communication between two systems on a network. To be a bit precise, a socket is a combination of IP address and port on one system. So on each system a socket exists for a process interacting with the socket on other system over the network. A combination of local socket and the socket at the remote system is also known a ‘Four tuple’ or ’4-tuple’. Each connection between two processes running at different systems can be uniquely identified through their 4-tuple.

There are two types of network communication models:

  1. OSI
  2. TCP/IP

While OSI is more of a theoretical model, the TCP/IP networking model is the most popular and widely used.

As explained in our TCP/IP Fundamentals article, the communication over the network in TCP/IP model takes place in form of a client server architecture. ie, the client begins the communication and server follows up and a connection is established.

Sockets can be used in many languages like Java, C++ etc but here in this article, we will understand the socket communication in its purest form (i.e in C programming language)

Lets create a server that continuously runs and sends the date and time as soon as a client connects to it.

Socket Server Example

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <time.h> 

int main(int argc, char *argv[])
{
    int listenfd = 0, connfd = 0;
    struct sockaddr_in serv_addr; 

    char sendBuff[1025];
    time_t ticks; 

    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&serv_addr, '0', sizeof(serv_addr));
    memset(sendBuff, '0', sizeof(sendBuff)); 

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(5000); 

    bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); 

    listen(listenfd, 10); 

    while(1)
    {
        connfd = accept(listenfd, (struct sockaddr*)NULL, NULL); 

        ticks = time(NULL);
        snprintf(sendBuff, sizeof(sendBuff), "%.24s\r\n", ctime(&ticks));
        write(connfd, sendBuff, strlen(sendBuff)); 

        close(connfd);
        sleep(1);
     }
}

In the above program, we have created a server. In the code :

  • The call to the function ‘socket()’ creates an UN-named socket inside the kernel and returns an integer known as socket descriptor.
  • This function takes domain/family as its first argument. For Internet family of IPv4 addresses we use AF_INET.
  • The second argument ‘SOCK_STREAM’ specifies that the transport layer protocol that we want should be reliable ie it should have acknowledgement techniques. For example : TCP
  • The third argument is generally left zero to let the kernel decide the default protocol to use for this connection. For connection oriented reliable connections, the default protocol used is TCP.
  • The call to the function ‘bind()’ assigns the details specified in the structure ‘serv_addr’ to the socket created in the step above. The details include, the family/domain, the interface to listen on(in case the system has multiple interfaces to network) and the port on which the server will wait for the client requests to come.
  • The call to the function ‘listen()’ with second argument as ’10? specifies maximum number of client connections that server will queue for this listening socket.
  • After the call to listen(), this socket becomes a fully functional listening socket.
  • In the call to accept(), the server is put to sleep and when for an incoming client request, the three way TCP handshake* is complete, the function accept () wakes up and returns the socket descriptor representing the client socket.
  • The call to accept() is run in an infinite loop so that the server is always running and the delay or sleep of 1 sec ensures that this server does not eat up all of your CPU processing.
  • As soon as server gets a request from client, it prepares the date and time and writes onthe client socket through the descriptor returned by accept().Three way handshake is the procedure that is followed to establish a TCP connection between two remote hosts. We might soon be posting an article on the theoretical aspect of the TCP protocol.Finally, we compile the code and run the server.

    Socket Client Example

    #include <sys/socket.h>
    #include <sys/types.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <arpa/inet.h> 
    
    int main(int argc, char *argv[])
    {
        int sockfd = 0, n = 0;
        char recvBuff[1024];
        struct sockaddr_in serv_addr; 
    
        if(argc != 2)
        {
            printf("\n Usage: %s <ip of server> \n",argv[0]);
            return 1;
        } 
    
        memset(recvBuff, '0',sizeof(recvBuff));
        if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        {
            printf("\n Error : Could not create socket \n");
            return 1;
        } 
    
        memset(&serv_addr, '0', sizeof(serv_addr)); 
    
        serv_addr.sin_family = AF_INET;
        serv_addr.sin_port = htons(5000); 
    
        if(inet_pton(AF_INET, argv[1], &serv_addr.sin_addr)<=0)
        {
            printf("\n inet_pton error occured\n");
            return 1;
        } 
    
        if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
        {
           printf("\n Error : Connect Failed \n");
           return 1;
        } 
    
        while ( (n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) > 0)
        {
            recvBuff[n] = 0;
            if(fputs(recvBuff, stdout) == EOF)
            {
                printf("\n Error : Fputs error\n");
            }
        } 
    
        if(n < 0)
        {
            printf("\n Read error \n");
        } 
    
        return 0;
    }

    In the above program, we create a client which will connect to the server and receive date and time from it. In the above piece of code :

    • We see that here also, a socket is created through call to socket() function.
    • Information like IP address of the remote host and its port is bundled up in a structure and a call to function connect() is made which tries to connect this socket with the socket (IP address and port) of the remote host.
    • Note that here we have not bind our client socket on a particular port as client generally use port assigned by kernel as client can have its socket associated with any port but In case of server it has to be a well known socket, so known servers bind to a specific port like HTTP server runs on port 80 etc while there is no such restrictions on clients.
    • Once the sockets are connected, the server sends the data (date+time) on clients socket through clients socket descriptor and client can read it through normal read call on the its socket descriptor.

    Now execute the client as shown below.

    $ ./newsc 127.0.0.1
    Sun Dec  18 22:22:14 2011

    We can see that we successfully got the date and time from server. We need to send the IP address of the server as an argument for this example to run. If you are running both server and client example on the same machine for testing purpose, use the loop back ip address as shown above.

    To conclude, In this article we studied the basics of socket programming through a live example that demonstrated communication between a client and server processes capable of running on two different machines.

Posted in Uncategorized | Leave a comment

Threads implementation with clients

RCS file: ipc_thrdsrvr.c,v
Working file: ipc_thrdsrvr.c
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;    selected revisions: 2
description:
—————————-
revision 1.2
date: 2014/03/31 11:58:38;  author: root;  state: Exp;  lines: +10 -10
implemented threads on two clients
—————————-
revision 1.1
date: 2014/03/31 11:53:46;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Project 04: FTP based Client Server using Threads and Sockets, Uncategorized | Leave a comment

Threads are used in performing IPC .And ipc technique is message ques

RCS file: server_thread.c,v
3 Working file: server_thread.c
4 head: 1.1
5 branch:
6 locks: strict
7         root: 1.1
8 access list:
9 symbolic names:
10 keyword substitution: kv
11 total revisions: 1;     selected revisions: 1
12 description:
13 this is server in which ipc is done
14 and threads are implemented in them
15 —————————-
16 revision 1.1    locked by: root;
17 date: 2014/03/31 10:18:07;  author: root;  state: Exp;
18 Initial revision
19 =============================================================================

Posted in Uncategorized | Leave a comment

pointer to function

whats the diffrenece between these two??
int *function (int)
int (*function) (int)

Posted in Uncategorized | Leave a comment