void Node::process_datagram(Packet p) throw(myExceptions) {
    
    cout<<"inside process_datagram\n";
    int cmd = p.getcmd();
    
    switch (cmd) {
        case GETSUCC:
            cout<<"GETSUCC\n";
            getsuccessor(p);
            break;
        
        case FOUNDSUCC:
            foundsuccessor(p);
            break;
            
        case GETPRED:
            getpredecessor(p);
            break;
            
        case SETPRED:
            setpredecessor(p);
            break;
            
        case SETSUCC:
            setsuccessor(p);
            break;
            
        case GETINDEX:
            getindex(p);
            break;
        
        case REQUSERS:
            requestusers(p);
            break;
            
        case SENDUSERS:
            sendusers(p);
            break;
            
        case DOWNREQ:
            downloadrequest(p);
            break;
            
        case SENDINFO:
            sendinfo(p);
            break;
            
        default:
            break;
    }
}
int main()
{
	int choice, v1, v2, v3, n, i, j, k;
	int c = 0;
	struct bstnode* root;
	root = NULL;
	scanf("%d", &n);
	int A[n];
	for(i = 0; i < n; i++) {
		scanf("%d", &v1);
		root = insert(root,v1);
	}
	inorder(root,A,&c);
	while(1) {
		printf("Choices:\n");
		printf("1. Inorder successor of node with value 'x'\n");
		printf("2. Inorder predecessor of node with value 'x'\n");
		printf("3. Exit\n");
		scanf("%d", &choice);
		switch(choice)
		{
			case 1:	
				printf("Enter the value of node of which the successor is required\n");
				scanf("%d", &v2);
				j = getsuccessor(v2,A,c);
				if (j == -99) {
					printf("%d has no inorder successor or it doesnot exist in the BST\n",v2);
				} else {
					printf("Successor of %d is: %d\n",v2,j);
				}
				break;
			case 2:	
				printf("Enter the value of node of which the predecessor is required\n");
				scanf("%d", &v3);
				k = getpredecessor(v3,A,c);
				if (k == -99) {
					printf("%d has no inorder predecessor or it doesnot exist in the BST\n",v3);
				} else {
					printf("Predecessor of %d is: %d\n",v3,k);
				}
				break;
			case 3:
				exit(1);
		}
	}
	return 0;
}