Popular Posts

Total Pageviews

Monday, August 12, 2013

Chrome doesn't set cookies for domain "localhost"

A recent problem has been popped up in chrome, since some time they don't allow user to set cookie for domain localhost. So if you are using this code in php for setting the cookie
setcookie ( $name , $value , $expire , $path , "localhost", $secure , $httponly )

then just change the above code to this
setcookie ( $name , $value , $expire , $path , "", $secure , $httponly )

or

setcookie ( $name , $value , $expire , $path , null, $secure , $httponly )


it will work and will not hamper your development activities. Anyway you are going to change this code on production.

Wednesday, July 6, 2011

inclusion of new files into patch and creation of patch on linux

Programmer who take part in some kind of big code needs to generate patch files. Begginers do get trouble here as how to create, there is simpple command on linux diff use that as follows
Suppose u have old code in oldmake folder and new code in home/newmake. Then follow these steps.
1. cd home
2. diff -urN /home/waste/oldmake newmake > patch1
Now you might have written some new file instead of modifying any file. There is no need to worry diff is already taken care of that stuff, your patch includes those files.

How to use patch
if you want to apply patch inside /home/checkmake then go to checkmake folder
1. cd /home/checkmake
2. patch -p patch1

Tuesday, June 28, 2011

ns2 installation, problems and solutions on fedora

One of the most easiest way to install ns2 is to download ns-allinone package. So download ns-allinone-2.34.tar.gz. now follow these steps.
1. go to directory where you saved tar.gz file and execute following command
tar -xzf ns-allinone-2.34.tar.gz
2. cd ns-allinone-2.34/
3. now install the package using (switct to root or use sudo)
./install
4. first problem you encounter is "g++ command not found" otherwise skip this step
soln- yum install gcc-g++
now try 3rd step again
5. you might encounter problem of "/home/user.../generic/tk.h:557: error expected declaration specifiers or '...' before 'Window' and similar other errors while installing tk (otherwise skip this step)
soln- yum install libX11-devel
now try 3rd step
6. if you get "can't find X includeds otcl-1.13 configuration failed! Exiting.."
soln- yum install libXt-devel or yum groupinstall "X Software Development" later one is better.
now try 3rd step and it will run successfully

Friday, June 17, 2011

using binary number in C or C++

Many C learner face the problem of initializing a variable with binary value or assign a integer variable with binary values. Don't worry its very easy as described in C you can use 0x for hex, 0 for octal similarly 0b defines binary. for example if you want to assign binary 1101 (i.e 13) to variable. then use this
int var = 0b1101;

Thursday, June 16, 2011

undefined reference to static variable in c++

Suppose i have a code which need to reference static variable
so we have following code in trial.h
class Trial
{
static int v;
void setCode();
}

in trail.cc
#include "trial.h"
void Trial::setCode()
{
v=1;
}

This above code will give undefined reference to Trial::v error. To remove this error either remove static word from v in .h file or if it is necessary to have static word. then do as following.
in trial.cc
#include "trial.h"
int Trial::v;
void Trial::setCode()
{
v=1;
}

now your error is gone . happy coding

Wednesday, December 15, 2010

How to send user data in ns2

If you are trying to send your own data (i.e user defined data) over a network in ns2 then you might have tried different function of Packet. If you have tried out allocating PacketData and setting it into Packet then it might have leaking the memory and eats up swap space and later processor time too. Generally for small data transfer it wont be able to figure it out but when you transfer data in order of 10 of MBs then you might face this challenge. You might have tried creating your own Packet type etc. if it works then its good but i don't think it will.
So what we can do?

Solution is that create your own application layer and transport layer well you can edit existing but those are might be used by other traffics and did not give proper results in other application which you don't want. Its always nice to create a new class. So derive a class from application layer and another class from transport layer.
Add one char * data and int size field in packet header.

In application read data from file and assign it to new pointer, create a packet and point data field of packet to this new pointer with size and send this packet to transport layer. At transport layer copy the packet header into newly created header (all existing transport layer always create a new packet) and send it normally to other existing layers with out any problem.

On receiving at transport layer either you can process it here or pass the header to application layer for further process. Now process the data in receive side of application layer and free the pointer pointed by data pointer of header. That's it and you are done.

Here goes the important part of the code but this is for UDP, similar things can be done on TCP (TCP code will look complex that's why i am uploading UDP code)
void mimoUdpAgent::sendmsg(int nbytes, AppData* data, const char* flags)
{
    Packet *p;
    int n;
    hdr_cmn cmn_buf = *(hdr_cmn *)flags;
    assert (size_ > 0);

    n = nbytes / size_;

    if (nbytes == -1) {
        printf("Error:  sendmsg() for UDP should not be -1\n");
        return;
    }   

    // If they are sending data, then it must fit within a single packet.
    if (data && nbytes > size_) {
        printf("Error: data greater than maximum UDP packet size\n");
        return;
    }

    double local_time = Scheduler::instance().clock();
    while (n-- > 0) {
        p = allocpkt();
        hdr_cmn::access(p)->size() = size_;
        hdr_rtp* rh = hdr_rtp::access(p);
        rh->flags() = 0;
        rh->seqno() = ++seqno_;
        hdr_cmn::access(p)->timestamp() =
            (u_int32_t)(SAMPLERATE*local_time);
       
        hdr_cmn::access(p)->last_ = cmn_buf.last_;
       
        hdr_cmn::access(p)->realPayload = cmn_buf.realPayload;
        hdr_cmn::access(p)->file = cmn_buf.file;
        hdr_cmn::access(p)->frame_id_ = cmn_buf.frame_id_;
        char buf[100];
        if(openfile!=0){
            hdr_cmn::access(p)->pkt_id_ = id_++;
        }
       
        // add "beginning of talkspurt" labels (tcl/ex/test-rcvr.tcl)
        if (flags && (0 ==strcmp(flags, "NEW_BURST")))
            rh->flags() |= RTP_M;
        p->setdata(data);
        target_->recv(p);
    }
    n = nbytes % size_;
    if (n > 0) {
        p = allocpkt();
        hdr_cmn::access(p)->size() = n;
        hdr_rtp* rh = hdr_rtp::access(p);
        rh->flags() = 0;
        rh->seqno() = ++seqno_;
        hdr_cmn::access(p)->timestamp() =
            (u_int32_t)(SAMPLERATE*local_time);
        hdr_cmn::access(p)->last_ = cmn_buf.last_;
        hdr_cmn::access(p)->realPayload = cmn_buf.realPayload;

        hdr_cmn::access(p)->file = cmn_buf.file;
        if (flags && (0 == strcmp(flags, "NEW_BURST")))
            rh->flags() |= RTP_M;
        p->setdata(data);
        target_->recv(p);
    }
    idle();
}
Note: Part of the code is copied from work of other person.

I have added many fields here but realPayload and last are important field. Last will tell the end of data and realPayload contains actual data transferred from application.

Friday, October 1, 2010

remote desktop on fedora from fedora client

Most of the times peoples don't always like to reach office or other machines where actual work is done. Suppose you have a very high resource machine located at some distance from your current place and you don't want to go there for work. Here i provide a way to people who don't how to remote fedora machines from fedora clients.

On client fedora machine:
"yum install tsclient"

you may require sudo permission to run above command.


On fedora server:

"yum install vnc-server"

this will install vnc server on your fedora machine. then set the password for your vnc server using below command

"vncpasswd"

this will prompt for a password. Enter the password which you want to use later when you trying to connect from fedora client. Now time to start your vnc server

"service vncserver start"

Now if you try to connect from client to this server using command
"vncviewer serverip"

it may give you "unable connect to socket: Connection refused (111)"

then use sudo permission on server to stop firewalls using
"service iptables stop"

now you all set to remote the server.

Note:- it may still shows "unable connect to socket: Connection refused (111)" in that case cancel your server at the current port and start the server with next port and try vncviewer serverip :port