রবিবার, ২৯ মার্চ, ২০১৫

ServerSocket Class Methods

The java.net.ServerSocket class is used by server applications to obtain a port and listen for client requests
The ServerSocket class has four constructors:
SNMethods with Description
1public ServerSocket(int port) throws IOException
Attempts to create a server socket bound to the specified port. An exception occurs if the port is already bound by another application.
2public ServerSocket(int port, int backlog) throws IOException
Similar to the previous constructor, the backlog parameter specifies how many incoming clients to store in a wait queue.
3public ServerSocket(int port, int backlog, InetAddress address) throws IOException
Similar to the previous constructor, the InetAddress parameter specifies the local IP address to bind to. The InetAddress is used for servers that may have multiple IP addresses, allowing the server to specify which of its IP addresses to accept client requests on
4public ServerSocket() throws IOException
Creates an unbound server socket. When using this constructor, use the bind() method when you are ready to bind the server socket
If the ServerSocket constructor does not throw an exception, it means that your application has successfully bound to the specified port and is ready for client requests.
Here are some of the common methods of the ServerSocket class:
SNMethods with Description
1public int getLocalPort()
Returns the port that the server socket is listening on. This method is useful if you passed in 0 as the port number in a constructor and let the server find a port for you.
2public Socket accept() throws IOException
Waits for an incoming client. This method blocks until either a client connects to the server on the specified port or the socket times out, assuming that the time-out value has been set using the setSoTimeout() method. Otherwise, this method blocks indefinitely
3public void setSoTimeout(int timeout)
Sets the time-out value for how long the server socket waits for a client during the accept().
4public void bind(SocketAddress host, int backlog)
Binds the socket to the specified server and port in the SocketAddress object. Use this method if you instantiated the ServerSocket using the no-argument constructor.
When the ServerSocket invokes accept(), the method does not return until a client connects. After a client does connect, the ServerSocket creates a new Socket on an unspecified port and returns a reference to this new Socket. A TCP connection now exists between the client and server, and communication can begin.

Socket Programming:

Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server.
When the connection is made, the server creates a socket object on its end of the communication. The client and server can now communicate by writing to and reading from the socket.
The java.net.Socket class represents a socket, and the java.net.ServerSocket class provides a mechanism for the server program to listen for clients and establish connections with them.
The following steps occur when establishing a TCP connection between two computers using sockets:

  1. The server instantiates a ServerSocket object, denoting which port number communication is to occur on.
  2. The server invokes the accept() method of the ServerSocket class. This method waits until a client connects to the server on the given port.

  3. After the server is waiting, a client instantiates a Socket object, specifying the server name and port number to connect to.
  4. The constructor of the Socket class attempts to connect the client to the specified server and port number. If communication is established, the client now has a Socket object capable of communicating with the server.
  5. On the server side, the accept() method returns a reference to a new socket on the server that is connected to the client's socket.
After the connections are established, communication can occur using I/O streams. Each socket has both an OutputStream and an InputStream. The client's OutputStream is connected to the server's InputStream, and the client's InputStream is connected to the server's OutputStream.
TCP is a twoway communication protocol, so data can be sent across both streams at the same time. There are following usefull classes providing complete set of methods to implement sockets.

সোমবার, ২৩ মার্চ, ২০১৫

Java Code চলতে বেশি সময় নেয় কেন?

জাভা কোড প্রথমে বাইটকোড এ কম্পাইল হয়, তারপর সেটিকে জাভা ভার্চুয়াল মেশিন এক্সিকিউট করে। বাইটকোড হচ্ছে এক ধরণের ইন্টারমিডিয়েড ল্যাংগুয়েজ যা কিনা ঠিক হিউম্যান রিডএবল ও না, আবার মেশিন রিডএবলও না। এটি শুধুমাত্র জাভা ভার্চুয়াল মেশিন (JVM) পড়তে পারে। বাইটকোড কে এক্সিকিউট করার জন্যে জাভা ভার্চুয়াল মেশিন জাস্ট ইন টাইম(JIT) কম্পাইলার ব্যবহার হরে। JIT বাইটকোড কে সরাসরি ইন্টারপ্রেট করে। এটি রানটাইম-এ বাইটকোড কে ইন্টারপ্রেট করে মেশিন কোড এ রূপান্তরিত করে যা কিনা সিপিইউ রান করে। এখানে একটি ইন্টারেস্টিং প্রশ্ন হতে পারে, জাভা কি তাহলে ইন্টারেপ্রেটেট ল্যাংগুয়েজ নাকি কম্পাইল্ড ল্যাংগুয়েজ? উত্তর কিন্তু দুটোই । জাভা একি সাথে কম্পাইলড এবং ইন্টারপ্রেটেড ল্যাংগুয়েজ।
উপরের লাইনগুলো পড়ে আপনি মনে করতেই পারেন যে, JIT আসলে জাভাকে স্লো করে দিচ্ছে, কারণ এটি প্রোগ্রাম যখন চলে তখন ইন্টারপ্রেট করছে। এই উপসংহার হয়তো ইনটিউটিভ, কিন্তু সঠিক নয়। JIT আসলে অনেক ভাল ভাবেই কাজ করে।
C/C++ সাধারণভাবে ধরা হয় যে জাভা এর থেকে বেশি ভাল পারফর্ম করে। জাভা যেহেতু অন-ফ্লায় এক্সিকিউট করে , এজন্যে অনেকটা এভাবে চিন্তা করা হয়। কোড-কে মেশিন কোড-এ রূপান্তরিত করার জন্যে আসলে খুব বেশি সময় লাগে না, তারপরও যদি কোন ল্যাংগুয়েজ এর কোড-কে এক্সিকিউট করার আগে তাকে মেশিন কোড এ রূপান্তরিত করতে না হয়, তাহলে ধরা হয়, সেই ল্যাংগুয়েজ অনেকটা ফাস্টার। মজার ব্যপার হচ্ছে কোন কম্পাইলার-ই কিন্তু টপ-নচ এসেম্বলি প্রোগ্রামাররা যারা কিনা কোন হার্ডওয়্যারকে কে টার্গেট করে মেশিন কোড সরাসরি মেনিপুলেট করতে পারে, তাদের মতো মেশিন কোড তৈরি করতে পারে না, যা কিনা অনেক বেশি পার্ফরমেন্ট হবে। C/C++ কিংবা জাভা সবগুলোর-ই কিছু না কিছু ইস্যুজ আছে। জাভাকে রান করার আগে অনফ্লায় মেশিন কোড তৈরি করতে হয়, C/C++ এর কোড ও কিন্তু অনেকটা জেনেরিক ভাবেই কম্পাইলড হয়। C/C++ এ কিন্তু সরাসরি একটি নির্দিষ্ট হার্ডওয়্যারকে টার্গেট করে কোড লেখা হয় না সবসময়।
মজার ব্যপার হচ্ছে, জাভা ভার্চুয়াল মেশিন কিন্তু খুব-ই ইন্টেলিজেন্ট এনভায়রনমেন্ট এবং JIT নিজেও খুব-ই ইন্টেলিজেন্ট কম্পাইলার। উদাহরণ সরূপ- JVM জানে যে কোন মেথড কতবার কল করা হচ্ছে, কারণ এটি কাউন্ট করে । যখন এই কাউন্ট একটি নির্দিষ্ট থ্রেসহোল্ড এর বাইরে চলে যায়, তখন সেই মেথড-এর মেশিন কোড JVM রেখে দেয়, পরের বার আবার কল করা হলে, সেটি আর সেই মেথডকে ইন্টারপ্রেট না করে সরসরি সেই রেখে দেওয়া মেশিন কোড-কে দিয়ে দেয় যা কিনা বারবার বাইটকোড থেকে মেশিনকোড-এ ট্রান্সলেশান করার কস্ট কমিয়ে দেয়। আরও মজার ব্যাপার হচ্ছে, JIT কম্পাইলার, যে সব কোড খুব বেশিবার ব্যবহার করা হয়, সেগুলোকে অপটিমাইজ করে । JIT নানা ধররণের স্ট্যাটিসটিক্স কালেক্ট করে থাকে। রিসার্সে দেখা গেছে যে, 80% সময়ে আসলে মোট কোডবেইস এর 20% কোড এক্সিকিউট করা হয়। সুতরাং এই 20% কোড গুলো যদি আলাদা করা যায়, এবং এদেরকে অপটিমাইজ করা যায়, তাহলে কিন্তু হিউজ পার্মমেন্স গেইন করা যাবে। মজার ব্যপার হচ্ছে JIT আসলে তাই করে। এটি (hotcode) এই ২০% কোড কে আলাদা করতে পারে এবং এদেরকে অপটিমাইজ করতে পারে। ওরাকল এর জাভা ভার্চুয়াল মেশিন হটস্পট এর নাম হয়তো অনেকেই জানি, এবং সেটি কিন্তু নামকরণ করা হয়েছে এই জন্যে যে, এটি এই হট স্পট গুলোকে আলাদা করতে পারে। জাভা যেহেতু JVM এর জন্যে লেখা হয়, এবং JIT সেটিকে মেশিন কোড এ রূপান্তরিত করে, এটি কিন্তু রানটাইমে হার্ডওয়্যার এর ইনফরমেশান একসেস করতে পারে এবং তার উপর ভিত্তি করে অপটিমাইজ মেশিন কোড তৈরি করে পারে, যা কিনা C/C++ এর ক্ষেত্রে অনেক সময়ই সম্ভব হয়ে উঠে না।
সুতরাং উপসংখ্যার হচ্ছে, জাভা আসলে অনেক বেশি পারফর্ম করে, কিন্তু সেটা হয়তো একটি ছোট হ্যালোওয়ার্ল্ড টাইপ এপ্লিকেশান লিখলে দেখা সম্ভব হবে না, কিন্তু আমরা যদি অনেক বড়ো বড়ো এপ্লিকেশান রান করি, এটি খুব ভাল ভাবে, অন্যান্য ল্যাংগুয়েজ থেকেও অনেক বেশি ভালভাবে কাজ করবে ।
Author : bazlur_rahman

শনিবার, ২১ মার্চ, ২০১৫

কম্পিউটার নেটওয়ার্কে ফাইল শেয়ার করবেন যেভাবে

অফিস কিংবা বাসায় কম্পিউটারের ফাইল অন্যের সঙ্গে শেয়ার করার প্রয়োজন হয়। এ ক্ষেত্রে একই নেটওয়ার্কে কম্পিউটারটি যুক্ত থাকলে আলাদা ডিভাইসের প্রয়োজন হয় না। সহজেই ফাইল ভাগাভাগি করা যায়। যদিও অনেকের ধারণা এ জন্য সার্ভার তৈরি করতে হবে। বিষয়টি মোটেও সেরকম নয়। সুনির্দিষ্ট কৌশল জানা থাকলে সার্ভার সিস্টেম না থাকলেও খুব সহজে একই নেটওয়ার্কে ফাইল শেয়ার করা যায়। কিভাবে ফাইল শেয়ারিং করতে হয় তা নিয়ে এ টিউটোরিয়াল।
ফাইল শেয়ারিংয়ের প্রথম শর্ত কম্পিউটারগুলোকে একই নেটওয়ার্কে সংযুক্ত থাকতে হবে। একই নেটওয়ার্কে থাকলে যে ফোল্ডারটিকে শেয়ার করতে হবে প্রথমে সেটিতে ডান ক্লিক করতে হবে। এরপর সেখান থেকে শেয়ারিং ট্যাবে ক্লিক করতে হবে। এরপর উইন্ডোজ এক্সপি অপারেটিং সিস্টেম হলে ‘অ্যালাউ নেটওয়ার্ক ইউজারস টু চেঞ্জ মাই ফাইল’ অপশনে টিক দেওয়ার পর সেখান থেকে নেটওয়ার্ক ব্যবহারকারী ঠিক করে দিতে হবে।
 উইন্ডোজ ৭ অপারেটিং সিস্টেম হলে অ্যাডভান্স শেয়ার নামের বোতামে ক্লিক করতে হবে। শেয়ার বোতামে ক্লিক করে অ্যাড মেনু থেকে এভরিওয়ান বাছাই করে শেয়ারে ক্লিক করতে হবে। তারপর অ্যাডভান্সড শেয়ার বোতামে ক্লিক করলে শেয়ার দিস ফোল্ডারে টিক দিয়ে ওকে করতে হবে।
এতে করে নেটওয়ার্কে ফাইলটি শেয়ার হয়ে যাবে। আর শেয়ার করা ফাইলটি দেখতে হলে ডেস্কটপ বা ফাইল এক্সপ্লোরার থেকে নেটওয়ার্ক আইকনে ক্লিক করতে হবে। একই নেটওয়ার্ক বা হোম গ্রুপে থাকা কম্পিউটারগুলো দেখা যাবে এতে। এবার নির্দিষ্ট কম্পিউটারে ক্লিক করলে সেখান থেকে শেয়ার করা ফোল্ডারটি দেখা যাবে।

রবিবার, ৮ মার্চ, ২০১৫

ওয়েব দুনিয়ায ব্যবহৃত কিছু শব্দের পূর্ণরূপ.


১। HTTP এর পূর্ণরূপ — Hyper Text Transfer Protocol.
২। HTTPS এর পূর্ণরূপ — Hyper Text Transfer Protocol Secure.
 ৩। IP এর পূর্ণরূপ— Internet Protocol.
৪। URL এর পূর্ণরূপ — Uniform Resource Locator. ৫। USB এর পূর্ণরূপ — Universal Serial Bus.
 ৬। VIRUS এর পূর্ণরূপ — Vital Information Resource Under Seized.
৭। SIM এর পূর্ণরূপ — Subscriber Identity Module.
৮। 3G এর পূর্ণরূপ — 3rd Generation.
 ৯। GSMএর পূর্ণরূপ — Global System for Mobile Communication.
 ১০। CDMA এর পূর্ণরূপ — Code Divison Multiple Access.
১১। UMTS এর পূর্ণরূপ — Universal Mobile Telecommunicati on System.
১২। RTS এর পূর্ণরূপ — Real Time Streaming
১৩। AVI এর পূর্ণরূপ — Audio Video Interleave
১৪। SISএর পূর্ণরূপ — Symbian OS Installer File
১৫। AMR এর পূর্ণরূপ — Adaptive Multi-Rate Codec
 ১৬। JAD এর পূর্ণরূপ — Java Application Descriptor
 ১৭। JAR এর পূর্ণরূপ — Java Archive ১৮। MP3 এর পূর্ণরূপ — MPEG player lll ১৯। 3GPP এর পূর্ণরূপ — 3rd Generation Partnership Project
২০। 3GP এর পূর্ণরূপ — 3rd Generation Project
২১। MP4 এর পূর্ণরূপ — MPEG-4 video file
 ২২। AAC এর পূর্ণরূপ — Advanced Audio Coding
২৩। GIF এর পূর্ণরূপ — Graphic Interchangeable Format
২৪। BMP এর পূর্ণরূপ — Bitmap ২৫। JPEG এর পূর্ণরূপ — Joint Photographic Expert Group
 ২৬। SWF এর পূর্ণরূপ — Shock Wave Flash
২৭। WMV এর পূর্ণরূপ — Windows Media Video
২৮। WMA এর পূর্ণরূপ — Windows Media Audio ২৯। WAV এর পূর্ণরূপ — Waveform Audio
 ৩০। PNG এর পূর্ণরূপ — Portable Network Graphics
৩১। DOC এর পূর্ণরূপ — Document (Microsoft Corporation)

৩২। PDF এর পূর্ণরূপ — Portable Document Format৩৩। M3G এর পূর্ণরূপ — Mobile 3D Graphics
৩৪। M4A এর পূর্ণরূপ — MPEG-4 Audio File
৩৫। NTH এর পূর্ণরূপ — Nokia Theme (series 40)
৩৬। THM এর পূর্ণরূপ — Themes (Sony Ericsson)
 ৩৭। MMFএর পূর্ণরূপ — Synthetic Music Mobile Application File
৩৮। NRT এর পূর্ণরূপ — Nokia Ringtone
৩৯। XMF এর পূর্ণরূপ — Extensible Music File
৪০। WBMP এর পূর্ণরূপ — Wireless Bitmap Image
৪১। DVX এর পূর্ণরূপ — DivX Video
৪২। HTML এর পূর্ণরূপ — Hyper Text Markup Language
৪৩। WML এর পূর্ণরূপ — Wireless Markup Language
৪৪। CD এর পূর্ণরূপ — Compact Disk.
৪৫। DVD এর পূর্ণরূপ — Digital Versatile Disk.
৪৬। CRT — Cathode Ray Tube.
৪৭। DAT এর পূর্ণরূপ — Digital Audio Tape.
৪৮। DOS এর পূর্ণরূপ — Disk Operating System.
৪৯। GUI এর পূর্ণরূপ — Graphical User Interface.
৫০। ISP এর পূর্ণরূপ — Internet Service Provider.
৫১। TCP এর পূর্ণরূপ — Transmission Control Protocol.
৫২। UPS এর পূর্ণরূপ — Uninterruptible Power Supply.
৫৩। HSDPA এর পূর্ণরূপ — High Speed Downlink Packet Access.
 ৫৪। EDGE এর পূর্ণরূপ — Enhanced Data Rate for GSM[Global System for Mobile Communication]
৫৫। VHF এর পূর্ণরূপ — Very High Frequency.
৫৬। UHF এর পূর্ণরূপ — Ultra High Frequency.
৫৭। GPRS এর পূর্ণরূপ — General Packet Radio Service.
৫৮। WAP এর পূর্ণরূপ — Wireless Application Protocol. ৫৯। ARPANET এর পূর্ণরূপ — Advanced Research Project Agency Network.
৬০। IBM এর পূর্ণরূপ — International Business management