Followers 0

# Android WiFi HotSpot server and client help

## 7 posts in this topic

Hello there guys,

I've been asking around on many forums asking for some help on an application I am trying to create, Let me first explain the functionally of the application I want to develop

Application :

This application will simply start a server and allow other android devices to connect to the device and play this application together, how I want this to work is, one user will use WiFi, I do apologize the title should not have WiFi hot spot, I just want to use WiFi to send data from one device to another.

Problems :

I have created a TCP/IP and a Multicast server with java, now looking at Android, Android of course runs java applications, but I don't know as I can't find information about it, if the same code to start a Multicast server will work on a mobile device. All I'm trying to do is, one user will set up a server socket to listen on where clients will connect, once they are connected a thread will be created, and constant data will be send back to the client, this was achieved quite quickly and simple using Java, but with Android I'm not sure if I can do the same code for pc to Android?

Here is the code I have so far, but I don't think this does much

wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);


I have looked at this http://marakana.com/forums/android/examples/40.html , it gives an example application, but it just sends data to itself, I want to know how I can setup a sock on a mobile device, which can be used to send and receive data via UDP protocol.

Any help would be great, I have had no help from anyone so far, and trying to find the right code example is like trying to find a pin in a haystack.

Canvas

Edited by Canvas
0

##### Share on other sites
Multicast does not work on the general Internet. The problem is that, to join a multicast group, my router has to know about that group, which means that every router on the internet needs to know about the multicast groups that any user on that router *might* want to join -- which is all of them.

Use TCP. And, evenso, if your Android host is behind a NAT gateway, you have to do NAT punch-through, which requires an external introducer.
0

##### Share on other sites

I'm using one of the devices as a Wifi hot-spot so that is the "router" as all clients first connect to that using WiFi, I don't want to use TCP because of the extra data being sent over, I want to just send fast and small packets, Would a datagramSocket be a bit easier to work with?

Edited by Canvas
0

##### Share on other sites
The protocol overhead of TCP vs UDP is unlikely to be measurable compared to all the other traffic on the network (IP overhead, WiFi overhead, ATM overhead on your cable or DSL, etc.)
That being said, you can use UDP if you want to. Many fine games use UDP. You have to remember that packets may not make it, or may be duplicated, or may be re-ordered, or all three.
0

##### Share on other sites

That is not a problem, with the data being send so often data can be lost and the effect will probably not be able to be seen by the naked eye. Also the reason I am asking if I should use a DatagramSocket instead of a MulticastSocket is, I have some code and when I run it I get this error

Java.net.SocketException: No such device

When I run this

try
{
}
catch ( IOException e )
{
Log.d(TAG, "Error code 0003");
e.printStackTrace();
}


MulticastSocket works like a radio where it keeps broadcasting it out which is good for my application, but I'm not sure if a DatagramSocket would just be easier because of networking issues.

0

##### Share on other sites
Yes; Multicast requires specific support from your network routers and will not work across the Internet.
0

##### Share on other sites

Yes; Multicast requires specific support from your network routers and will not work across the Internet.

He isn't attempting to do it across the internet though, Assuming the server is a wifi hotspot that the clients all connect to both broadcast and multicast will work just fine.

a Multicast Socket in Java is a Datagram(UDP) socket with the ability to join groups.

The groups address is NOT the same as the servers address(common mistake), multicast groups use reserved addresses between 224.0.0.0 and 239.255.255.255

The error the OP is getting is most likely due to "address" either not being a proper InetAddress object or it not being created with a valid multicast address.
0

##### Share on other sites

Well I'm going to try and create what I did using a DatagramSocket instead of a MulticastSocket, if I get any errors, the code will be put in this topic. Cheers for all the information people.

0

## Create an account

Register a new account