Monday, 26 October 2015

What Is a Socket?


'**A server application normally listens to a specific port waiting for connection requests from a client. When a connection request arrives, the client and the server establish a dedicated connection over which they can communicate. During the connection process, the client is assigned a local port number, and binds a socket to it. The client talks to the server by writing to the socket and gets information from the server by reading from it. Similarly, the server gets a new local port number (it needs a new port number so that it can continue to listen for connection requests on the original port). The server also binds a socket to its local port and communicates with the client by reading from and writing to it.The client and the server must agree on a protocol--that is, they must agree on the language of the information transferred back and forth through the socket.


Definition: A socket is one end-point of a two-way communication link between two programs running on the network.

**The java.net package provides two classes--Socket and ServerSocket--that implement the client side of the connection and the server side of the connection, respectively.
          Definition:              A socket is one endpoint of a two-way communication link between two programs running on the                        network. A socket is bound to a port number so that the TCP layer can identify the application that data               is destined to be sent to.

Friday, 9 October 2015

Serialization vs Synchronization


Serialization is used whenever you try to store an object in a file or suppose
you want to transfer an object from one application to another application via
network in that case you serialize an object so whenever a object is serialize
it make sense because it can be transferred over the network and it can be
persisted. This is very important whenever data is transferred across the
network or you want to store it in a file right to a file. Synchronization is
whenever multiple thread that trying to access object or instance or method
then there might be problem for concurrency issues because it may happen that
once I just trying to modify the value of a variable and at the same time
another thread is trying to read it so in those cases we try to use
synchronized keyword over a block of code or over a method so that only one
thread can access that method at a time and all other threads have to wait so
only when this current thread exist the method and releases the control to
other threads in waiting.

In Other way:

Synchronization is a concurrency issue, e.g. how do you coordinate access to an object from multiple threads.

Here an arrow represents access.

                            s
 [thread1] ---------------> y
                            n [shared object]
 [thread2] ---------------> c
                            h
Serialization is the conversion of data structures and objects into a sequence of bits that you can store/transmit and then convert back to data structures and objects.

Here an arrow represents conversion.

            deserialization
           <---------------
  [object]                  [binary]
           --------------->
            serialization
This is most useful when the deserialization happens at another place and/or time.