The multi threaded socket classes

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

1. INTRODUCTION

Definition of the problem

This research mainly deals about the multi threaded socket classes between the client and the server. In this the concept called threads are used by the developer but it is optional as its not yet decided whether it needs or not. Even detection can provide the feedback to the application where the socket classes and the other internet cannot provide. The following are the event detection methods provided: establishing the connection, dropping the connection, the information about the fail of the connection and data reception (including 0 byte packet).

About the Project and Description

The TCP and UDP communication is supported by new socket classes which are created in this research. Some advantages are been provided than compared to the some other classes on the internet or on the other socket programming classes. There is no limitation that the use of the window handling is necessary. That is this research has no such limitations. The threading process is been automatically supported to handle the socket connection and as well as disconnection. Special options have been used in the socket classes which have been not introduced till now. Both server sockets and the clients socket are supported in this research. A socket which is connected to the server is called as client socket and a socket which accepts many connections are called as the server socket. Two applications can be communicated without the connection by using these classes. UDP server sockets are created in this process (for each and every socket only one application). in this classes the coding is also been reduced in order to create an application like chatting etc and for the inter process communication in between server or client and or on more applications or processes. With the support of TCP/IP the communication in among two peers is established with an error handling. The destination data is been controlled while transmitting by using a smart addressing operation that is by UDP only. Communication between the two peers can only be dealt by TCP operation.

Analysis of Network Client Server

IP datagram's

A connectionless and unreliable delivery system is provided by the IP layer .Each data gram is considered independent of the others. The higher levels are used to supply the connection between the datagrams. Checksum is supplied by the IP layer which contains its own header. The contents of the header are source and destination addresses. Routing is handled by the IP layer through an Internet. It is also responsible for breaking up large datagram into smaller ones for transmission and reassembling them at the other end.

UDP

This is connectionless and unreliable. Checksum and port numbers are added to the IP in this UDP. client/server model is given by the use of the UDP .

TCP

TCP is a connection oriented protocol .It is a reliable network used above the IP. In TCP to establish a communication between two processs a virtual circuit connection is been provided .

Internet addresses

Internet uses the address scheme at which it can be placed. The 32 bit integer address is been used which gives the IP address, where the network ID and the their address can be encoded. Depending upon the size of the network address the network ID can fall into various different classes.

Network address

An address scheme is used by the internet at which they will be positioned. The 32 bit integer address is been used which provides us with the IP address, at which network ID and address is encoded. The network ID comes under different classes depending upon the network address size.

Subnet address

Internally, the UNIX network is alienated into different sub networks. Building 11 is at present on one sub network and having 1024 different host and 10-bit addressing.

Host address

Within the subnet the host address uses 8 bits. Its ranges is 0 - 256 machines which can be placed on subnet.

Port addresses

A service is identified by its port as it exists on a host exists on a host.Which is of 16 bit number. If a message need to be send to the server it should be first sent to port of the host service on which it is running on. These are well known as they are not location transparent.

Sockets

In this the network connections are handled and it is like a data structure maintained by the system. Using the function called call socket the socket is been created. An integer is returns a number which is a file descriptor. This windows can be handled by the ReadFile and WriteFile functions.

Here the integer "family" is used for IP communication which is an AF_INET ,where protocol is defined as zero, and depends on which protocol is used i.e whether TCP or UDP. On a network when two processes wants to communicate then a socket is need to be created each.

Module Design Specification

Part 1 - Here we are going to connect client and server where the server sockets listens the client.

Part 2 - Sending and receiving data between the client and the server.

Part 3 - Unknown size file of data of the client is read in this part.

Create a server socket to establish a connection between the client and server:

Socket (int af, int type, int protocol)

This method creates the socket bind (SOCKET s, const struct sockaddr FAR * name, int namelen) connect to a local address to the socket .The custom is used on distinct datagram or on stream socket, prior to following functions of connects or listens. No name has been assigned if the socket is created by using another socket and this exists in a name space (address family). A local name is assigned to unnamed socket by using a function called bind which establishes a local connection of the (host address/port number) .A name has several components on the internet address. It consists of three main parts: a host address, protocol number (set implicitly to UDP or TCP, respectively), and a port number these are the main function that are present in the SOCK_DGRAM and SOCK_STREAM which identify the application. It's important that the application should known what address is been allocated to it so that the internet address does not show INADDR_ANY i.e. if port is zero. Any suitable network interface can be used I if the address of the internet is equal to INADDR_ANY, which simplifies the application programming in occurrence of multiple hosts. A unique port value is allocated to an application by using window sockets execution if the port is indicated as 0 within the range value of 1024 and 5000. After bind Getsockname is used by the application to now the address that has been allocated to it but until the socket is connected the process will not plug in the internet address. This is because as internet addresses are valid only if the host is multiple homed. If errors are not present then the bind returns the value as 0. A particular error code is been retrived by calling the function WSAGetLastError if not it returns as SOCKET_ERROR.

listen(SOCKET s, int backlog )

A socket is been established to listen the incoming connection .A socket is created by another socket to accept the connections. The connections are accepted by a function called accept before the backlog for the inward connections are specified with the listen function , and then the connections are accepted with accept. The socket that supports the connections are applied by the listen socket i.e. the function like SOCK_STREAM. The acknowledgment of the incoming connection and the acceptance by the process is done only if the socket is in the passive mode. This function can be used by the server that has one or more connection request which is processed at a time. The client will receive a error if the connection request is full with an indication of WSAECONNREFUSED. When there are no descriptors available then the listen will function rationally.

The connection is allowed till the queue is empty. The queue will be re-filled by the call for the listen/accept functions for the present or the recent "backlog''. The descriptors become available, and start again listening for the incoming connections if possible.

accept (SOCKET s, struct sockaddr FAR * addr, int FAR * addrlen)

A connection which is on the top of the queue is extracted and connected on the server s, with the same properties the new socket is created as the new socket is handled by the server s . the function accept stops the client to communicate if the socket is not marked unblocking and in the queue if the delay connections are not present. The function accepts returns an error if there no further connection presents in the queue and if the unblocking is marked in the socket. A very large number of connection are not been accepted bye the socket called accept socket. The socket which is original remains open. The address of entities that are connected are filled by the parameter called argument addr which are known as communication layer.. the parameter addr is extracted from the family of address through which communication processdone . The addrlen function is initially pointed to the parameter addr and in result it gives use the definite length of address in bytes. The result is in value parameter. This is used with connection-based socket types such as SOCK_STREAM. If there is no information regarding the remote address which is present in the accepted socket then it means that addr and /or addrlen both are pointing to NULL .

close socket(SOCKET s)

closes a socket

Making connection to the client and the server:

In exception with the HOSTENT structure a socket is been created in order to connect to another socket which can make use of the function used in the previous code.

HOSTENT:

To which port and to which computer the socket should be connected is described in this HOSTENT structure. These structure is initialized as LPHOSTENT, and it is directly pointing to the pointer HOSTENT .These are the pointer of HOSTENT.

Client key function:

To establish the connection between the client and server some of the functions are used as the same function are used for the server for the exception as a few. The different functions that are been used by the client is described in this research.

gethostbyname(const char* FAR name)

To a hostnet structure a pointer is returned by gethostbyname as described by gethostbyaddr. The above mentioned structures contents are used to communicate to hostname. The Windows Sockets implementation owns the pointer which returns the points to the structure. The modification of the structure or the attempt to free of the components in the application should never be done. Before issuing any window socket API calls the request should copy the information which is required as only one replica of the structure is owned per thread. Passing an IP address strings to window socket API calls should not be resolved by the performance of the function gethostbyname. Such an appeal is to be treated accurately as an unidentified host name was passed. The function called inet_addr is used to convert the string into IP address and is also used to resolve the IP address string in an application , Then gethostbyaddr to obtain the hostent structure.

Part 2 - To send and receive the messages between the client and the server

In the part 1 there is a description about the connection between the client and the server.. The connection between the client and the server is not enough in the real time application. The communication between the client and the server and its application and the use and the information about how to send and receive the function is described in this section. The main difficulty in this research is setting up the server and the client application and establishing the communication is not much difficult. The details about the below mentioned two functions must be known before going the coding.

send(SOCKET s, const char FAR * buf, int len, int flags)

here on a socket to write the outgoing data stream sockets or datagram are been connected to write the data. There should be concerned for the datagram sockets, that the size of the underlying subnets should not be exceed the maximum IP packet , that is specified by iMaxUdpDg component in the WSAData structure returned by the WSAStartup.

No data is transmitted if the error as WSAEMSGSIZE is returned this happens .And the information pass ed will be atomically passed through the underlying protocol if the data is too long.

recv(SOCKET s, const char FAR * buf, int len, int flags)

SOCK_STREAM is a type of socket, in which the information can be accessible until the buffer size supplied is returned and can't be used further. If in the socket is configured in such a way that the out of band data is unread and for in- line function of unavailable data (socket option SO_OOBINLINE) ,then the returned data will the unavailable data. The application may use the function ioctlsocket SIOCATMARK is used to determine if any of the unavailable information is left to read.

Part 3 - Unknown size file of the data is been read.

As mentioned in part 2, exchange of the messages that is to send and receive the message between the client and the server is performed. Previously the difficulty was that the idea about the size of the data was not known and the problem would have end up along with the problem without being solved.

A new function is created to fix in order to obtain a pointer to the user socket and then at a time the character is read and then placing each and every character into some other address space until we get the '\n' character which indicates that the message has been end.

The one way to start reading the unknown size of the data is to read the data from one socket to the other socket as it is not as tough or industrial way to solve the problem. After the accept method the task will be called.

Java is a highly used programming language as Java programs can be both compiled as well as interpreted. During the compilation process Java byte code is used to translate java program into an intermediate language .To run the java program in the computer the platform-independent code instructions are passed

Every time when the program is been executed interpretation may occur but Compilation happens only once.

For the Java Virtual Machine (Java VM) java byte code can be used as the machine code instructions. Java VM has implemented many tools like web browser java development tool and as well the Java interpreter that can run java applets. Java VM can also be implemented in the hardware.

Java byte codes has a possibility that the program can be written once and it can run anywhere .Java programs can be complied as byte codes on any platform on any computer if the java complier software is installed it in as java is an platform independent. Any implementation of the java VM can then be run by the byte codes .For example, on Windows NT, Solaris, and Macintosh in this the java programs can be runned.

JAVA PLATFORM

A program runs on a software or hardware environment which is called as a platform. Beside the other hardware based platform software is the only one platform that run on top of all these as Java platform different from most of other platforms . A combination of hardware and operating system is been described in most of the other platforms.

Java platform contains two components:

  1. Java VM which is called as The Java Virtual Machine
  2. Java API which is called as the java application programming interface.

Java VM is already described. For the Java platform java VM is treated as the base and it is presented onto different hardware-based platforms.

The API in java provides us with many facilities such as GUI widgets which is a graphical user interface as it is a large group of software components

The Java API is grouped into libraries (package) of related components. The next sections, what can Java do? Highlights each area of functionally provided by the package in the Java API.

The below figure depicts a Java program, such as an application or applet, that's running on the Java platform. Server is a kind of application which has the capacity to serve and provide with the components to the clients which is on a network. Examples of the servers include Web Servers, proxy servers, mail servers, print servers, and boot servers. One of the specialized programs in this Servlet the runtime extension of an application is common in both the servlet and on the applets. Servlet run in the java web server which is used for configuring of server instead of working with the browsers.

How java API supports all this kind of programs?

Software components contain some packages which has the capability to provide a high range of functionality. Each and every implementation of the platform is included in the API

The following features are provided by the core API:

The Essentials: Objects, Strings, threads, numbers, input and output, data structures, system properties ,date and time ,and so on.

Applets: Java applets uses as set of conventions.

Networking: URL's TCP and UDP sockets and IP addresses.

Internationalization: It can be used for writing the programs which are limited to a small area for users within the localized area.

Specific locations are adapted for the Worldwide programs which can be displayed in different kinds of languages.

  • JAVA PROGRAM
  • Java API
  • Java Virtual Machine
  • Java Program
  • Hard Ware

From hardware dependencies java program can insulate the API and Virtual Machine. Java can be little bit slower then native code as java is a platform independent environment. Without disturbing the functions of the portability the java performance can be improved by using smart compilers, well-tuned interpreters, and Just-in-time-byte-code compilers.

WHAT CAN JAVA DO?

However, Java is not just for writing cut, entertaining applets for the World Wide Web (WWW). Java is a used as general purpose, high-level programming and a powerful software platform. Using the fineries Java API, you can write many types of programs.

Java application is an individual program that runs on the java platform directly as applets and applications are the most common type of programs.

Security:

Both low-level and high-level, including electronic signatures, public or private key management, accesses control, and certificate.

Sequence diagrams:

Reviews in analysis: In general, the software development process starts with requirements gathering and analysis. In this phase, business analyst category people will develop BRS and SRS. Before going to design, the same analyst people are conducting review meetings to estimate the completeness and correctness of that document. In this review the business analyst people are applying below check list on that BRS and SRS

  • BRSà SRS
  • Are they complete?
  • Is these requirements are right ?
  • Can these are Achievable?
  • Whether they are reasonable?
  • Are they testable

Reviews in design: After completion of analysis and their reviews, designing category people are developing the HLD's and LLD's. After development of these documents, the same category designers will conduct a review meeting to estimate the completeness and correctness of the design documents.

HLDàLLD

  • Are they understandable
  • Are they Complete
  • Are they meet right requirements
  • Are they follow able[w . r .t coding]
  • Are they handling Errors?

White box testing: It is a program testing technique. During the white box testing, responsible people are verifying the internal structure of the corresponding program. This testing in also known as open box testing.

Black Box Testing: It is a build level testing. During this test, responsible people are validating the external functionality of complete software.

This Black Box testing is also known as closed box testing.

The combination of white box and black box is called grey box testing.

Software Testing: The verification of the software development process and validation of software product before release to customer is called software testing.

Unit Testing: In this testing the coding will be started by the corresponding programmer after completion of the reviews and the design. To construct software physically in this coding stage, corresponding programmers are verifying the internal structure of every program with the help of white box testing technique. The white box testing techniques are clarified into 4 divisions

  • Basis Path Testing
  • Control Structure Testing
  • Program Technique Testing
  • Mutation Testing

Basis Path Testing: After completion of program writing the corresponding programmer follows below approach to verify the execution of every statement in that program

Program Testing Technique: Whether the corresponding program is taking less time to complete execution or not. Programmer are using java and .net profiles to calculate execution time of the program

Mutation Testing: Change in the program by the logic / coding is called mutation. Programmers are using this Technique to confirm whether that program completely tested or not. After changes, if the testing is effected, then the program is complete.

Integration testing: After completion of individual programs development and unit testing, programmers are inter connecting them or integrating them to form a system (i.e a complete software). The other name for the integration testing is also called as interface testing. There are 4 approaches in this integration Top down approach [ STUB]

  • Bottom up approach[ DRIVER]
  • Hybrid approach
  • Big bang approach

Top down approach: In this approach, programmers are interconnecting main module with some of sub modules. In the place of remaining under constructing sub modules, programmers are using temporary programs called STUBS. These STUBS are also known as programs

Bottom up approach: In this approach, programmers are interconnecting sub modules without using under constructive main module. In this approach, programmers are using a temporary program instead of main module called DRIVER, which is also known as calling program.

Hybrid approach: It is also known as sandwich approach. This is a combined approach of top down and bottom up approach.

Big Bang Approach: it is also known as system approach. In this approach, the programmers are inter connecting programs after completion of all programs development and unit testing.

Case Study:

Top down approach is follow able when the requirements are changing dynamically

Bottom Up approach: It is follow able when the customer requirements are constant but architecture is changing

Hybrid approach: It is follow able when the requirements and architecture both are constants

If our system consists of less number of interconnections in between the modules, at that situation big bang approach is follow able.

System Testing: After completion of integration testing, development people release initial build to separate testing team in that organization. This separate testing team follows black box testing to validate the requirements of the customer in that build, the system testing classified into three divisions such as

  • Usability testing
  • Functional testing
  • Non Functional testing.

Usability testing: In general, the separate testing team is starting software testing through validation user friendliness. This usability is testing is classified into below sub tests.

User interface testing:

Ease to use [ understandability of screen of elements]

Look and feel [attractiveness of the screen elements]

Speed in interface [ to complete a task less number of events are present]

During this test, test engineers are concentrating on above factors to be applied on every screen [i.e window] build

Manual support testing: In this separating testing team is validating the correctness and completeness of corresponding user manual or help document w.r.t to build operations. Receive build from developers

Functional Testing: This part is a mandatory level in system testing phase. In this part the separate testing team is concentrating on "requirements meeting in build"

Functionality testing: This is also called as "Requirement testing" During this test, test engineers are validating the correctness of every functionality through below coverage's.

GUI Coverage : changes in properties of objects in screen's

Eg: 1st cursor highlighted in username, it will come to password and after that ok button.

This total execution is under this coverage.

Error Handling Coverage: Preventing wrong operations. If we enter any wrong user id and password then it will give u error message as invalid password.

Input domain coverage: Correctness of size and type of inputs.

Output manipulations coverage : correctness of functionality outputs

Back end coverage or Data base coverage: on back end tables the impact of front end operations are described.

Service level coverage: [ functionality of order]: when the object should response and when it should not.

Sanitation testing: The other name for this is garbage testing . During this test, test engineers are detecting extra functionalities in that applications build with respect to requirements.

Non functional Testing: After completion of all possible usability and functional test, testing team is concentrating on other quality factors to validate in that application or product [build].

Recovery testing : The other name for this is reliability testing during this test, test engineers are checking whether our application build is changing from abnormal state to normal state or not

Inter system testing: It is called as end to end testing, during this test, test engineers are verifying whether the application build is sharing common resources along with the other applications build. If there are no common resources, then test engineers are not applying this testing.

Security testing: The other name for this is penetration testing during test , test engineers are validating

  • Authorization
  • Access control
  • Encrypt and decrypt

Authorization: For user validation to connect to application eg : login with password, digital signature, pin no ,finger prints etc.

Access Control : For authority of valid users to access specified services or functionality eg : administrator and user

Encrypt and decrypt : used for code conversion between client and server processes

Compatibility: This is known as portability testing. During this test, test engineers are testing that whether our build is run on all customer expected plat forms or not. Plat form means that operating system, compiler, browser and other system software's.

Configuration Testing: This is known as hardware compatibility testing. During this test, test engineers are verifying that whether our build is run with different technology hardware devices or not.

Eg: Different technology networks, different topology [arrangement of computers different technology printers etc.

Load Testing: The execution is build under the customer projected configuration and customer predictable load to estimate routine is called load testing or scalability testing or capability testing. Load or scale means the number of concurrent users, which are accessing or operating our build.

Stress Testing: The execution of the build customer expected configuration and various levels from low to peak to estimate consistency or reliability in process is called stress testing. [ long time whether application is respond load or not]

Storage Testing: The other name for this is memory testing. During this test, testing people are calculating peak limit of storage handled by our build to store user data.

Eg: ms-access technology builds support 2gb data base as maximum. In terms of bytes.

Data volume testing: During this test, testing people are calculating the size of data in terms of number of records handled by our build.

Parallel Testing: It is also known as competitive testing or comparative testing. During this test, test engineers are comparing our build with old versions of some product or with similar products in market to find competitiveness.

Installation testing: During this test, test engineers are validating correctness and completeness of installation process of our build into customer expected configuration systems.

If the communication is taking place in a network and if it is written in java programming then the programming is done in the application layer. UDP and TCP layers are not much concerned by yourself . In the java.net package these classes can also be used as a substitute. The system-independent communication is also provided in this network. The difference between the TCP and UDP should be known first to decide which java classes should be used for the program.

TCP:

If the two parties want to send and receive the messages between them reliably they must set up a connection between each other to send and receive the messages through this connection. This is similar as making a phone call.A connection should be made in order to speak to person1 in a particular area. When person2 make a dial to person1 he/she will answers. After dialing a connection will be established and they can speak to each other on the phone lines. Here in this process there can be an assurance that the data that has been sent is the same when it reaches to the destination and this is provided by the TCP protocol i.e. the way as the person1 has sent.

TCP provides a reliable communication to the end-to-end channel for applications. The reliable communication channel is required for the Hypertext Transfer Protocol (HTTP), File Transfer Protocol (FTP), and Telnet are all examples of applications .The success of this application is difficult in order to send and receive the data over the network. When HTTP reads from URL the data should reach the destination in the same way as it was sent .Otherwise, it ends up if the file is corrupted zip file or if the file is contains any invalid data or the information.

Definition: TCP is defined as the reliable and the connection oriented protocol where the data can be exchanged between the two systems. It is also called as Transmission Control Protocol.

UDP

Here in the UDP protocol provides the communication between the client and the server is not been guaranteed on the network. UDP is connectionless-oriented protocol as of like TCP. Rather, datagram's are sent and packets of the data are transferred, from one stages of application to another. As each message is independent of the other there is no guarantee the message has been sent or it has been received same as sending the letters through the postal service.

Definition: UDP is a User Datagram Protocol. This protocol produces a small number of individual packets of data which is called as datagram. Which are transferred from one computer to the other computer without any guarantees about arrival. UDP is a connectionless protocol and not like TCP.

For many applications, there is no guarantee that the information sent from on system to the other is successfully reached or not that is reliability is not present in the UDP. However, such strict standards are not required for the other form of communication. The communication may also get slow down if the connection in the service is not reliable and there is an extra overload.

Consider, for example, current time is been sent to the client when the clock serve is requested . The client can get an incorrect time if he is missing a packet and it may send the wrong time when it is requested for the next time. If a request is sent by the client to the server and if the server sends the packets which are not available currently then that makes no difference to the client as the client has the right to send another request to receive the available packets from the server. The consistency of TCP is redundant in such a case it may causes performance degradation and might delay the utility of service.

Ping command can be taken as an example for dependable channel. The ping command is used to test the communication between two programs over a network. Ping command needs to know about dropped or out-of-order packets to decide whether the connection is good or bad. This service will

Invalidate the reliable channel anyway.

Two applications on a network has no guarantee that they can communicate using the UDP protocol . UDP is connectionless protocol. But independent packet is sent from one application to the other application. Sending datagram can be taken as an example as posting post by the mail service: The ordering of delivery is not important, as each and every message has its own identity.

Note: Many firewalls and routers have been configured not to allow UDP packets. If there is any problem connecting to provide the service outside the firwall or if the problem in connecting the service there is a need for the system administrator to check w whether the user datagram protocol is allowable or not.

Understanding the Ports

In general, only one network is connected to the computer a through the physical connection. All the data which is needed for the system to access is provided by this connection. However, information may be projected for various applications will be running on computer. So how a particular system can know to which application the data needs to be sent? By using the ports one should know.

Address information identifies the system and a port number to which the data needs to be transmitted over the Internet for the particular destination. Here the 32 bit IP address is used for the computer to deliver the data to the a particular computer on the network. 16-bit number is identified by the TCP and UDP to deliver the data to the correct application.

In TCP a socket is been bind by a server application to specify the port number as TCP is a connection oriented protocol. To receive the data which is intended on that port it should first register with the server of that computer. The server and the client can communicate with the help of server's port, as shown in figure:

Definition: for a particular process running on the computer ports are been used by the TCP and UDP protocols get the incoming data.

In datagram-based communication, the datagram contains the destinations port number so that the UDP routes the packet to the particular destination or application, as shown in this figure:

Ports are represented by 16 bit numbers which ranges from 0 to 65,535 which are taken as port numbers. HTTP and FTP and other system services are the well known services and the port numbers ranging from 0 - 1023 are not been used as they restricted .The applications should not effort to bind them

TCP and UDP can communicate over the internet by java programming by the java.net classes. For the communication over the net URL, URL Connection, Socket, and ServerSocket classes are used. UDP uses the DatagramPacket, DatagramSocket, and MulticastSocket classes.

What is meant by Socket?

Normally, A socket is a class that has a particular specified port numberand which runs only on a specified server itself. To make a connection request the server listens and waits for the socket.

On the client-side: the hostname of the machine on which it is running and the port number on which the server is listening is known by the client. The client should assign with the server machine on the sever side and the port in order to make a connection .to bind a local port number during the connection the client needs to identify itself to the server.

If each and every application is set in a correct manner than the server accepts the connection. To the same local port to which the clent is connected a new socket is bound through the server and sets the address by the remote end point and the port of the client is connected upon acceptance of the server.to continue to listen to the riginal socket the server gets the new socketfor the connection request while it need to the connected client.

If the connection is accepted by in the client side the socket is successfully created and now this socket can be used for the communication between the client and the server.

From their sockets the client and server can communicate by writing to or by reading the data or the messages.

Definition: A socket is defined as a link between two programs which are running on a network between one endpoint of a two-way communication . TCP layer can identify the application to which the data needs to be sent as the socket is bound to a port number.

An endpoint is a combination of an IP address and a port number. By the two end points every TCP connection can be uniquely identified. Multiple connections can be established between the client and the server through this way.

Here an implementation for the connection between the java program and the some other program in a network can be possible. As java.net package provides a class, Socket in the java platformto implement. In the platform dependent implementation the Socket class will be on top as it has the capacity to hide the details of the system from the java program. Java is a platform-independent the programs which are implemented will also be in the same fashion over a network instead of relying on the native code by using the java.net.socket.

Additionally, the server can listen and accept the connection to the client by implememting a socket which is present in the java.net which contains the ServerSocket class. The use of the Socket and ServerSocket classes are described in this process.

The URL class and related classes (URLConnection, URLEncoder) are probably more appropriate if trying to connect to a web then the socket classes. Here, sockets are used as a part of underlying implementation as URLs are comparatively high-level implementation to the Web .connecting to the web through the URLs for getting the URLs information is shown below.

Description on the server socket

This section describes about the server and the coding in the program and the client that goes with it. Knock Knock jokes are served by the server in the client/server pair. Knock Knock jokes are special for children and are usually used for vehicles. They go like this:

Two independently running Java programs are shown in the above example: the client program and server program. A single class is implemented in the client program. A single class is been implememted by a client program, KnockKnockClient, and is very alike to the EchoClient .KnockKnockServer and KnockKnockProtocol,the server program makes use of this two classes . The main methods in the server program mainly contains this class KnockKnockServer, listen for the work on to the port, reading from the client and writing on to the server establishing connections. The jokes are served by the knockknockprotocol. It implements a protocol where the client and the server agreed to communicate .

The detailed description about the classes in the client and the server are shown to run the program.

The Knock Knock Server

Knock Knock server code is implemented is been described. The description about the source for the KnockKnockServer class is given.

The server socket object is created by the server program to listen on a specific port (the statement which is in bold letters in the code describes ). Choose a port in such a way that it should noy be dedicated to some other service before writing a server. KnockKnockServer listens on port 4444 because 4 happen to be my favorite number and port 4444 is not being used for anything else in my environment:

ServerSocket is a java.net class that provides a system-independent implementation of the server side of a client/server socket connection. An exception in present in the constructor for ServerSocketwhen it cannot listen to a specified server socket. (for example, if it is an already used port ). In sucha a situation KnockKnockServer should be exit from the program.

If the ServerSocket object is successfully created that means the server is been bind to the port successfully to the next step-that is accepting a connection from a client (shown in bold)

The accept method waits until a client starts up and requests a connection on the host and port of this server (in this example, the server is running on the hypothetical machine taranis on port 4444). The accept method returns a new Socket object which is bound to the same local port and has it's remote address and remote port set to that of the client when the connection is requested and established successfully. The client connection request can be listened on the original serversocket even though the server is communicating with the client over the new socket. More client connection requests programs are not listened by this particular version. In supporting multiple clents a modified version of the program is provided.

Step 1 is already described in the above section.

Step 2 is shown as to identify some comments and which are indicated in bold . The conversation with the client is initiated with the bold letters in the coding segment. The code creates a KnockKnockProtocol is an object created in the code which contains the tracks of current statements and the current state of the process.

After the KnockKnockProtocol is created, and to get the process Input method and the first message from the server to the client the code calls the KnockKnockProtocol's . For this example, "Knock! Knock!" is the first thing said by the server. Printwriter is allied to client socket and server writes the information to it in order to send the messages to the client.

While loop is encoded in the step3.

The server reads from and writes to the socket until the communication is going on between the client and the server and the messages are been sent and received between the client and the server.

The conversation is initiated by the server by using the "Knock! Knock!" the client should say "who is that? ". As the input stream is iterated on a read in the while loop. After getting the reply from the server then the client writes to its output stream as the readline method will wait (the server's input stream). KnockKnockProtocol object receives the responds of the client sent by the server when client responds and asks the KnockKnockProtocol object for a suitable reply. Using the output stream connected to a socket, the server sends a reply immediately by using a call to println. If the reply from the KnockKnockServer object is "Bye." That is the client is not interested in listening to any joke and can abort from the loop.

The server which is used in the KnockKnockServer is a supporting one .The work allocated to the KnockKnockServer will be finished in a given time period. Which involves the concepts like input and output streams, the client socket, and the server socket:

The KnockKnockProtocol class provides a protocol which provides the communication between the client and the server. Server and the client will be in there conversation and sending the server response to the client is placed in a track in this classes. The KnockKnockServer object this is used in such a way that client reply in a proper way to the server statement as it contains the text of all the jokes. It would not want the client say "person1 who?" when the server asks as "Knock! Knock!"

The messages which are passing in between all the client and the server will become meaningless if they do not have some protocols through which the client and server can communicate.

Client and the server are accomplished by which will be entirely dependent on the protocols that they are using.

The Knock Knock Client:

The KnockKnockClient class outfit the client program that can talk to KnockKnockServer. In the previous section KnockKnockClient is based on the EchoClient program , it should be in such a way that the server should read from socket and write to a socket and should be similar to the program using at the moment.

But regarding the program observation must be kept in the client as well as on the server context.

Before starting the client program, the server should be in a ready mode as it should be running as well as listening to a port, waiting for the client to send a request connection. The socket which is connected to server needs to be opened by the client program running on the hostname and port specified:

When creating its socket, KnockKnockClient uses the host name taranis, the name of a hypothetical machine on our network. The host name should be changed on to the machine name on the network before we type in and run the program. KnockKnockServer is runned on this machine .

The port number 4444 is specified by the KnockKnockClient program. This is called as a remote port number-which is the number on the server machine-and KnockKnockServer is listening to this port as well. To the any available local port the client's socket is bound and also to the port on the client machine. During this process server gets a new socket as well. On its machine the socket is bound to the port number 4444. The server's and the client sockets are connected.

The communication between the client and the server is done by the while loop. The server is the first one to communicate and the client is the listener. Th process starts when the client reads the input stream attached to the socket. If the server starts speaking, it says "Bye." and the client exits from the while loop. Otherwise, before user typing the standard input the client displays the text to the standard output and then it reads the response from the user. The client sends the text to the server through the output stream attached to the socket after the user type a carriage return .The communication ends when the server asks if the client wishes to hear another joke, the client says no, and the server says "Bye."

The server program should run first. In this,using the java interpreter run the server program, as such using any other java application. Server should run on a machine when it creates a socket which is specified by the client program.

Next, client program should be run on the machine. Note on machine in your network the client program can run; there is no restriction that it should run on only particular machine as the server.

The client can start before the server can initiate itself and start listening to the port .A stack trace from the client can be seen during this process. Then the client should be restart again.

In KnockKnockClient program if the host name is not changed in the source code then the following error will occur

Not known about the host: taranis

To do this, modify the KnockKnockClient program and provide a suitable host name for the network. Before trying again recompile the client program. The first client should be connected to the server, the second client should not start because it may get hang up.

The next section, Supporting Multiple Clients, and communication between them is described.

The below text will be displayed on the screen if the connection between the client and the server is successfully done:

The client sends the same message what has been typed and send the same message to the server. After receiving many Knock Knock jokes the server responds with its first line in its repertoire. The below text will be displayed in the screen (the text you typed is in bold):

To keep the KnockKnockServer example simple, it is designed in such a way that it can handle and can listen only the single connection request. However, the request from different client come and allocate in the same port and, as a result, can also use the same Server Socket. The server should accept the connections in an order as the Client connection requests are queued at the port. However, the server can serve them concurrently by the use of threads - one thread per each client connection.

Describing about the unknown size of the file :

Through the process of stream all the input and the output exchange of information can be taken place in java. Flow of data is called as an input stream . It is also used to produce data as well. Different kinds of streams are provides in java each are designed in such a way that they can handle various types of data or information. InputStream and Output Stream are the most probably used stream schemes to pass the data to and forth. Different kinds of data streams can also be created but most probably used datastreams are DataInputStream and the DataOutputStream which are used to read and write the primitive data types which provides with the flexibility to control the application execution results.

To increase the performance in the output or the input stream File buffers are used. A large amount of data can be read by the BufferedInputStreams and BufferedOutputStreams in which the size can be defined at a time. We are reading the data and writing the data on the buffer stream but not on the actual data on the stream. But it should be make sure that the data has to be completely read and written on the file system in the buffer. Using the stream data can be exchanged between one or more applications .In such cases the concept called pipes are been used in which there will be two end points .A message can be sent from one application to the other application as in a pipe one input end is connected directly to the other end of the connection i.e the output end.If the data is written on the input end it can be read on the output end of the file.

This is mainly used to promote interapplication communication.

Files should be stored in the local file system. Here FileInputStream and FileOutputStream are used to read, write and open the files. The file streams can manipulate only by the applications as the java is strictly restricted on the applet security. The stream classes cannot be processed if the file are not manipulated. For running applets here java capable browsers are used which provides the security mechanisms which are defined in the security model. These prevent unguarded file access discussed in the model "Java and Security" .The files can be manipulated if we are not writing the applet program in it.

The Basics

Three steps are involved When reading a file and when writing a files, they are as follows:

  1. for reading and writing a file should be opened .
  2. read from the file or write to the file ..
  3. after completion the file should be closed.

Each and every step involved in the above process are very important as if the file is unable to open then it is not possible to read the file. But not as by instinct, as the file must be still closed or the file may be wreck from the file system. A certain number of file descriptors are present for each and every application which gives us the status of the file. The file can be opened as long as the file descriptors are available if not the files cannot be opened. The below mentioned class fileReader is used to read the messages present in the file which are specified in the program.

By using the PrintWriter class, a Java console program can be written as:

References:

  1. http://www.codeproject.com/KB/IP/serversocket.aspx?msg=3038357
  2. http://www.codeproject.com/KB/IP/server_client_sockets.aspx
  3. http://www.infm.ulst.ac.uk/~kevin/com347/knock.htm
  4. http://dbserv.jinr.ru/js/content/java/New-tutorial/getStarted/intro/definition.html
  5. http://blog.csdn.net/wildwolf113/archive/2007/04/18/1568794.aspx
  6. http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html
  7. http://www.aldenhosting.com/JAVAtutorial/networking/sockets/clientServer.html
  8. http://www.docstoc.com/docs/12928070/JavaAdvanced
  9. http://www.mathcs.duq.edu/simon/Primer/getStarted/intro/definition.html
  10. http://www.iam.ubc.ca/guides/javatut99/getStarted/intro/definition.html
  11. http://www.codeproject.com/KB/cpp/multithreadedclientserver.aspx
  12. http://karthikeyan.terapad.com/index.cfm?fa=contentNews.newsDetails&newsID=36469&from=archive
  13. http://www.freepatentsonline.com/6574503.html
  14. http://www.selectorweb.com/java_io.html
  15. http://www.infm.ulst.ac.uk/~kevin/com347/q&a3.htm
  16. http://journals.ecs.soton.ac.uk/java/tutorial/networking/sockets/clientServer.html
  17. http://www.faqs.org/patents/app/20090161680
  18. http://www.aldenhosting.com/links/unix-hosting-1.html
  19. http://www.oser.org/~oser/ds/node24.html
  20. http://www.aldenhosting.com/links/create-web-page-1.html
  21. http://www1bpt.bridgeport.edu/sed/projects/cs597/unfiled/Ling/index.html
  22. http://hepunx.rl.ac.uk/~adye/javatutorial/networking/sockets/clientServer.html
  23. http://www.mediavue.net/programming/programLanguage/compProg/java_programming.html
  24. http://articles.techrepublic.com.com/5100-10878_11-6182101.html
  25. http://www.zdnetasia.com/techguide/printfriendly.htm?AT=62039856
  26. http://www.builderau.com.au/program/java/soa/Achieve-seamless-socket-programming-in-Java/0,339024620,339278470,00.htm
  27. http://www.eng.nene.ac.uk/~gary/javatut/networking/overview/networking.html
  28. http://www.nakov.com/inetjava/lectures/part-1-sockets/InetJava-1.1-Networking-Basics.html
  29. http://java.sun.com/docs/books/tutorial/networking/overview/networking.html
  30. http://v1.dione.zcu.cz/java/docs/tutorial/networking/overview/networking.html
  31. http://inetjava.sourceforge.net/lectures/part1_sockets/InetJava-1.1-Networking-Basics.html
  32. http://www.aldenhosting.com/JAVAtutorial/networking/overview/networking.html
  33. http://www.codeproject.com/info/search.aspx?artkw=udp
  34. http://www.freepatentsonline.com/7391770.html
  35. http://www.devasp.net/net/search/display/category74942_page15.html
  36. http://www.ibiblio.org/winsock/winsock-1.1/winsock.html
  37. http://www.dinf.ne.jp/doc/english/Us_Eu/conf/csun_99/session0002.html
  38. http://journals.ecs.soton.ac.uk/java/tutorial/networking/sockets/definition.html
  39. http://java.sun.com/docs/books/tutorial/networking/sockets/definition.html
  40. http://www.eng.nene.ac.uk/~gary/javatut/networking/sockets/definition.html
  41. http://life.csu.edu.au/java-tut/networking/sockets/definition.html
  42. http://life.csu.edu.au/java-tut/networking/sockets/definition.html
  43. http://java.sun.com/developer/technicalArticles/Streams/ProgIOStreams/
  44. http://developer.novell.com/support/winsock/doc/chap4pt2.htm
  45. http://www.slideshare.net/phanleson/socket-programming-2189026
  46. http://arcad.essi.fr/cours/Turorial%20Java/networking/sockets/definition.html
  47. http://www.site.uottawa.ca/~qingchen/106/95_106%20Notes%207%20-%20Networking.htm
  48. http://www1bpt.bridgeport.edu/sed/projects/cs597/unfiled/asyed/index.html
  49. http://learning.londonmet.ac.uk/CCTM/CC3008N/mulhollm/im257/im2577.htm
  50. http://cyberkinetica.homeunix.net/os2tk45/winsoc11/048_L3_bind.html
  51. http://babek.info/libertybasicfiles/lbnews/nl95/8.htm
  52. http://www.javafaq.nu/java-article1040.html
  53. http://www.nsu.ru/education/iit/tcpip/WinSock.htm
  54. http://www-user.tu-chemnitz.de/~heha/cgi-bin/viewzip.cgi/hs_freeware/winsock.zip/WINSOCK.DOC?auto=TXT
  55. http://www.coderanch.com/t/206105/Sockets-Internet-Protocols/java/Knock-Knock-Client

Bibliography:

Mastering C#.Net by Jason Price, Mike Gunderloy.

Beginning .NET 1.1 with Visual C# .NET 2003 By Chris Ullman, John Kauffman, Chris Hart.

Writing Services

Essay Writing
Service

Find out how the very best essay writing service can help you accomplish more and achieve higher marks today.

Assignment Writing Service

From complicated assignments to tricky tasks, our experts can tackle virtually any question thrown at them.

Dissertation Writing Service

A dissertation (also known as a thesis or research project) is probably the most important piece of work for any student! From full dissertations to individual chapters, we’re on hand to support you.

Coursework Writing Service

Our expert qualified writers can help you get your coursework right first time, every time.

Dissertation Proposal Service

The first step to completing a dissertation is to create a proposal that talks about what you wish to do. Our experts can design suitable methodologies - perfect to help you get started with a dissertation.

Report Writing
Service

Reports for any audience. Perfectly structured, professionally written, and tailored to suit your exact requirements.

Essay Skeleton Answer Service

If you’re just looking for some help to get started on an essay, our outline service provides you with a perfect essay plan.

Marking & Proofreading Service

Not sure if your work is hitting the mark? Struggling to get feedback from your lecturer? Our premium marking service was created just for you - get the feedback you deserve now.

Exam Revision
Service

Exams can be one of the most stressful experiences you’ll ever have! Revision is key, and we’re here to help. With custom created revision notes and exam answers, you’ll never feel underprepared again.