Thursday, November 29, 2007

Presario V3000 TV settings S-Video PAL

Before starting ...
+ Make sure you have installed Nvidia GeForce Go 6190 drivers.
+ Plugged the TV in via the S-Video Port.

1.
Right click and select Laptop Display from the NVidia Display menu.


2.
Choose the desired option
+ Clone : makes the same screen on your laptop display and on the TV screen.
+ Dual View: makes your TV the extension of your laptop display, ie., the TV together with your laptop becomes a big screen.


+ Apply the changes.

3.
+ If your TV does not work, select the TV, click the Device Settings, Select TV format, Advanced
+ make sure you have put the correct TV output. PAL/B in this case and that
the Video output format as S-video.


Apply changes and you should see the changes on your screen.

:)

Asynchronous Reading from Input

Intro
Normal working of a C program taking an input is done via the scanf method. The problem in scanf is that when we invoke scanf it waits until we input something i.e, our program is waiting for the user input. This valuable time could be used for processing other things. Let us consider an example of a chat client made using C. When we want to send some message we type them and send. In all other cases it is required that the chat client listens for incoming messages. This is impossible using the normal scanf method, because at all times it would be waiting for our input and there would not be any recieved messages in that time period. So the process of receiving information while checking for input is an example of asynchronous reading.

How ?

On Windows ...
On windows the input STDIN can be tested for data by the function kbhit()
defined on conio.h. A simple program template would be


#include <conio.h>

int main()
{
//...
while(1) //Main Process loop
{
//Other Process Block
{
/*
* Something else to do
*/

}
if(kbhit())
{
//Input present and process input
}
}
}

kbhit does not take any arguments, it returns 1 if there has been a keyboard hit i.e., a key has been pressed.
The key can be read using getch() or similar functions.

On Linux...
the same thing seems to be a bit different. There is no conio.h defined for linux so there is no kbhit function that can be used in linux. However linux has a set of functions that can be used to test any input for the presence of input. The following is the list of functions that are used to test the input for data.

#include <sys/time.h>

int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *errorfds, struct timeval *timeout);

void FD_SET(int fd, fd_set *fdset);

void FD_CLR(int fd, fd_set *fdset);

int FD_ISSET(int fd, fd_set *fdset);

void FD_ZERO(fd_set *fdset);

Sunday, November 18, 2007

Happy Birthday Digitalpbk

18th November 2007, Internet : Digitalpbk.blogspot.com is entering its one year of enthusiasm. Although digitalpbk started the first post on November 2nd, it started its official statistics(counter) by 18th November. Since it there has been
80000+ visitors,
80 posts,
230 + comments,
etc...

Thanks everyone 4 visiting my blog
that drives the drivers to make me post more ........
:)

Keep visiting ...
digitalpbk.

Sunday, November 4, 2007

UNIX Networking : Sockets TCP Transmitter and Reciever

Intro

Networking in UNIX or Linux is done with sockets. The following are 2 programs I made up.
1. Sends messages in TCP, Client
2. Listens and Recieves messages from TCP, Server

TCP or Transmission Control Protocol is a 2way connection which is more like a stream or a pipe. Both the ends must be connected.


The Transmitter
Reads messages from input and sends it to localhost:34000.
To Setup a transmitter following must be done:
1. Setup a port address and open a socket and bind to it.
2. Connect to server
3. Send messages
4. Close connection when done

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

/*Some are unused, But I read these are
general headers used in a network program
:)*/

int main(void)
{
struct sockaddr_in sin;
int s;

s = socket(AF_INET, SOCK_STREAM, 0);
if(!s)
{
perror("socket()");
return 1;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(9999);
sin.sin_addr.s_addr = INADDR_ANY;//Just any would do

if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
{
perror("bind()");
return 1;
}

struct sockaddr_in sout;

sout.sin_family = AF_INET;
sout.sin_port = htons(34000);//Destination PORT!
sout.sin_addr.s_addr = inet_addr("127.0.0.1");//Destination IP Address, here localhost.

connect(s,(struct sockaddr *)&sout, sizeof(sout));//Connect to Server
char msg[1000];//Buffer

do
{
printf("Message: ");
scanf("%s",msg);
sendto(s, msg, strlen(msg)+1, 0,NULL,0);
//Sends the message
}while(*msg!='0'); /*Just an exit condition*/

close(s);//Close Socket

return 0;
}


The Reciever
This program listens to localhost:34000 and accepts first connection and prints the messages whenever it recieves one.
To Setup a reciever following must be done:
1. Setup a port address and open a socket and bind to it.
2. Listens for Clients to connect.
3. Accept connections
4. Recieve data
5. Close connection

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

int main(void)
{

struct sockaddr_in sin;
char msg[10000];
int ret;
int sin_length;


int s,s2;

s = socket(AF_INET, SOCK_DGRAM, 0);
if(!s)
{
perror("socket()");
return;
}
sin.sin_family = AF_INET;
sin.sin_port = htons(34000);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
{
perror("bind()");
return 1;
}
if(listen(s,10))//Listen for connections
{
perror("listen()");
return 1;
}
int size=sizeof(sin);
if((s2=accept(s,(struct sockaddr *)&sin, &size) < 0))//Accept connections
{
perror("accept()");
return 1;
}
printf("\nConnected to %s[%d]",inet_ntoa(sin.sin_addr),sin.sin_port);

do
{
ret = recv(s2, msg, 10000, 0);
//Waits until a message is recieved...
printf("Message : %s\n", msg);
}
while(msg[0]!='0');

close(s);//Close Socket
return 0;
}


Thats all
Tested and proved working on Fedora Core 6.
Do let me know your results and comments.....
To know more about the functions check the Linux Manual for each function.

Check out... (UDP Transciever)
:)