Contact Us

Communication over WiFi In Android

What is WiFi?

WiFI or Wireless Fidelity is a technology that allows computers, smartphones or other devices to connect to the Internet or communicate with each other wirelessly within a particular area.Many facilities are provided by WiFi and hotspot is one of them.

What is Hotspot?

A hotspot is a wireless network(WLAN) that provides Internet connection and virtual private network access from particular location. For e.g. Employee connect their own company network remotely with a secure connection or group of people connected to one network for playing game,chat etc

Hotspot in Mobile Device

Mobile hotspots (portable hotspot) are portable devices or features on smartphones that provide wireless Internet access on many devices (like laptop, smartphone, tablet, portable gaming device, etc.)

Wireless chat application using portable WiFi hotspot

The Android platform provides support for the wireless network, which allows a device to wirelessly connect with other device and exchange data between them. The application framework provide wireless APIs for accessing wireless functionality. These APIs help for connecting devices wirelessly to each other, like point-to-point and point-to-multipoint communications.

This application allows two or more Android devices to communicate with each other without using any resources (like Internet ,chat servers). For communication between them we need tethering or hotspot.

Purpose of this application is making wireless communication between android devices. We need minimum two device for communication. One device enables tethering(via wifi). So we called is server and another device connect via wifi so we called client. If you want to connect more than two device. It is possible and it become group chat. To open a connection between devices, you need to make tcp/ip connection using a Socket and ServerSocket in Java.These Class are provided by java. If you want to use library for simplify coding then you can use it.

A socket is a software endpoint that establishes communication between connected nodes.

It can be two or more node(device). But primary stage one device is server that created socket which contain port for running services and ip address for connection purpose,and another device is client which connect to server.

Code Snippet and Requirements:

1) Android 2.2 or higher version(hotspot required)

2) Application Permission Require :

3) Create Hotspot:

4) Join Hotspot

5) Socket

i)Socket Class
Socket
ServerSocket
DatagramSocket
MulticastSocket(Required for multicast or group communication)

ii)Server Socket
The ServerSocket provide a listening TCP connection. Once a connection is requested, the ServerSocket object will return as Socket object representing the connection.

Constructors:
The ServerSocket provides four constructors. Empty construction means port number assigned by OS. With one argument port number take as argument to listen for connection requests. A constructor is provided facility of maximum time to wait for a connection as a second argument.And at last InetAdress or IP Address take as last argument.

Methods:
The most important method is accept(). It returns a Socket that is connected to the client. The close() method give idea of whether operating system to stop listening for requests on the socket.Some methods available for retrieve the hostname, port number etc.

iii) Client  Socket(Socket)

Socket Class provides a TCP connection. When a socket is created, a connection is opened to the specified destination, it can be domain name or ip address with specific port number.

Constructors:

The Socket provides the programmer with multiple constructors.

Empty socket is system default socket with the system-default type of SocketImpl. Another two constructors is Proxy and SocketImpl as single argument. Main focus is InetAddress constructor which may be specified as a string or an InetAddress, and the port number on the host to connect to. In each case, connection type is described as connectionless or not as set false for connectionless.

Methods:

Socket provides two methods are getInputStream() and getOutputStream(), which give return type as  stream objects, which help to communicate through the socket. Object provided virtual link to the socket.The close() method give idea of whether operating system to stop listening for requests on the socket.Some methods available for retrieve information about the connection to the local host and remote port numbers and an integers representing the remote host.

Sachin Patel

Sachin Patel | Android Developer

I am an Android Developer at Yudiz Solutions Pvt. Ltd. - a mobile App Development company. I am passionate about android app development and like adopting new technologies to maximize development efficiency and produce innovative applications.

Leave a Reply

Top
Yudiz Solutions Pvt. Ltd.
Career
Are you looking for a company where you are appreciated for your work?
Get a Free Quote
Tell Us Your Project Requirements

Career
Are you looking for a company where you are appreciated for your work?
Get a Free Quote
Tell Us Your Project Requirements