Data Transmission Using Multi-Tasking-Sockets Abstract
Data Transmission Using Multi-Tasking-Sockets Abstract
ABSTARCT:-This Project a new socket class which supports both TCP and UDP
communication. But it provides some advantages compared to other classes that you may find
here or on some other Socket Programming articles. First of all, this class doesn't have any
limitation like the need to provide a window handle to be used. This limitation is bad if all you
want is a simple console application. So this library doesn't have such a limitation. It also
provides threading support automatically for you, which handles the socket connection and
disconnection to a peer. It also features some options not yet found in any socket classes that I
have seen so far. It supports both client and server sockets. A server socket can be referred as to
a socket that can accept many connections. And a client socket is a socket that is connected to
server socket. You may still use this class to communicate between two applications without
establishing a connection. In the latter case, you will want to create two UDP server sockets (one
for each application). This class also helps reduce coding need to create chat-like applications
and IPC (Inter-Process Communication) between two or more applications (processes). Reliable
communication between two peers is also supported with TCP/IP with error handling. You may
want to use the smart addressing operation to control the destination of the data being transmitted
(UDP only). TCP operation of this class deals only with communication between two peers.
EXISTING SYSTEM: The thread is optional since the developer is still responsible to decide if
needs it. There are other Socket classes here and other places over the Internet but none of them
can provide feedback (event detection) to your application like this one does. It provides you
with the following events detection: connection established, connection dropped, connection
failed and data reception (including 0 byte packet).
PROPOSED SYSTEM: This article presents a new socket class which supports both TCP and
UDP communication. But it provides some advantages compared to other classes that you may
find here or on some other Socket Programming articles. First of all, this class doesn't have any
limitation like the need to provide a window handle to be used. This limitation is bad if all you
want is a simple console application. So this library doesn't have such a limitation. It also
provides threading support automatically for you, which handles the socket connection and
disconnection to a peer. It also features some options not yet found in any socket classes that I
have seen so far. It supports both client and server sockets. A server socket can be referred as to
a socket that can accept many connections. And a client socket is a socket that is connected to
server socket. You may still use this class to communicate between two applications without
establishing a connection. In the latter case, you will want to create two UDP server sockets (one
for each application). This class also helps reduce coding need to create chat-like applications
and IPC (Inter-Process Communication) between two or more applications (processes). Reliable
communication between two peers is also supported with TCP/IP with error handling. You may
want to use the smart addressing operation to control the destination of the data being transmitted
(UDP only). TCP operation of this class deals only with communication between two peers.
This routine extracts the first connection on the queue of pending connections on s,
creates a new socket with the same properties as s and returns a handle to the new
socket. If no pending connections are present on the queue, and the socket is not
marked as non- blocking, accept blocks the caller until a connection is present. If the
socket is marked non-blocking and no pending connections are present on the queue,
accept returns an error as described below. The accepted socket may not be used to
accept more connections. The original socket remains open. The argument addr is a
result parameter that is filled in with the address of the connecting entity, as known to
the communications layer. The exact format of the addr parameter is determined by the
address family in which the communication is occurring. The addrlen is a value-result
parameter; it should initially contain the amount of space pointed to by addr; on return
it will contain the actual length (in bytes) of the address returned. This call is used with
connection-based socket types such as SOCK_STREAM. If addr and/or addrlen are
equal to NULL, then no information about the remote address of the accepted socket is
returned.
closesocket(SOCKET s)
closes a socket
In order to create a socket that connects to an other socket uses most of the
functions from the previous code with the exception of a struct called HOSTENT
HOSTENT:
This struct is used to tell the socket to which computer and port to connect to.
These struct can appear as LPHOSTENT, but it actually means that they are pointer to
HOSTENT.
Most of the functions that have been used for the client to connect to the server are
the same as the server with the exception of a few. I will just go through the different
functions that have been used for the client.
Up to this point we have managed to connect with our client to the server. Clearly
this is not going to be enough in a real-life application. In this section we are going to
look into more details how to use the send/recv functions in order to get some
communication going between the two applications.
Factually this is not going to be difficult because most of the hard work has been
done setting up the server and the client app. before going into the code we are going to
look into more details the two functions
send is used on connected datagram or stream sockets and is used to write outgoing
data on a socket. For datagram sockets, care must be taken not to exceed the maximum
IP packet size of the underlying subnets, which is given by the iMaxUdpDg element in
the WSAData structure returned by WSAStartup. If the data is too long to pass
atomically through the underlying protocol the error WSAEMSGSIZE is returned, and
no data is transmitted.
Us mentioned earlier in part 2, we are noe going to expand on the way that we
receive data. The problem we had before is that if we did not know the size of data that
we where expecting, then the would end up with problems.
In order to fix this here we create a new function that receive a pointer to the client
socket, and then read a char at the time, placing each char into a vector until we find
the '\n' character that signifies the end of the message.
This solution is clearly not a robust or industrial way the read data from one socket
to an other, because but its a way to start reading unknown length strings. the function
will be called after the accept method
Requirement Specification:-
Language: JDK1.3