Skip to main content

Posts

Showing posts from October, 2014

Broadcast data using UDP in Java Socket Programming

If we want client to automatically discover server IP,we can do this by broadcasting a data packet with some identifier to the server , server extracts the client IP and then server send some identifier to the client ,client then extracts the IP from the packet received from the server.Here are simple work flows that is similar to DHCP protocol:- On the server side:- 1.) Open a socket on the server that listens to the UDP request. 2.) Make a loop that handles the UDP request and responses. 3.) Inside the loop,check the received UDP packed to see if its valid by identifier. 4.) Still inside the loop , send a response to the IP and port of the received packet. On the client side:- 1.) Open a socket on a random port. 2.) Loop over the computer network interfaces and get their broadcast address. 3.) send the UDP Packet inside the loop to the interface's broadcast address. 4.) wait for a reply 5.) when we have a reply , check to see if the package is valid. 6.) When its v...

Perfect Hashing and its implementation in C

Perfect hashing simply means hashing with no collision.But there is nothing like perfect hashing(no collision).These are just a work around to achieve perfect hashing.Using this we can able to search the large set of records in a constant time i.e O(1) time complexity.To achieve searching in strict O(1) time ,one needs to implement hash table and then search the given record in to hash table using hash function.         Here in perfect hashing ,one need to implement two level hash table , first level hash table consist a set of pointers that points to the second level hash table,we must select hash function that first maps the key in to first level hash table,so it simply means there must be collision in first level hash table ,thats  why i am saying its just a work around to achieve prefect  hashing.We must wisely choose hash function:                  h(x)=((a*x+b)mod p)mod m x is the key to be map, Here ...