7

I need a tutorial on how to process data on android via wifi. F.e., I need to send some message to PC and receive some other message. How should I establish the connection? What should I do to be able to transfer data and how?

Sorry for the dummy question, but I can't find good manual. I'll be grateful for as detailed manual as possible, or for ome simple example on etablishing wifi connection and sending/receiving simple mesages.

Yury Pogrebnyak
  • 4,093
  • 9
  • 45
  • 78
  • 3
    Learn Socket Programming. There's nothing special about `Wifi` on Android. It's basic Socket Communication. – st0le Dec 09 '11 at 09:11
  • 1
    If Wifi is enabled and you are connected to the Network, just use Java Socket classes for network communication. – HectorLector Dec 09 '11 at 09:17
  • Then how can I connect to wifi network? I haven't found any connect() method() in API. – Yury Pogrebnyak Dec 09 '11 at 09:22
  • You have to Learn P2P Connection Programming – sam_k Dec 09 '11 at 09:23
  • I posted snippets of code [here, how to connect to wireless][1]. It maybe will help you [1]: http://stackoverflow.com/questions/12973872/how-to-connect-to-a-wireless-network-in-android/12975100#12975100 – Maxim Shoustin Oct 19 '12 at 13:27

1 Answers1

17

You don't have to use any API for connect to wifi its only requires if you want to manually start your wifi in device,

Just make sure your device has a WiFi enable, and make a simple TCP/IP Socket application. With this you can communication with your system and device, And Use System's public IP to connect with your system.

Also don't forget to give permission Internet in your manifest file..

Here some nice links for Socket Programing in Android..

Simple connection example part II - TCP communication

Networking with Android

Simple communication using java.net.Socket

http://www.anddev.org/tcp_sockets-t276.html

http://www.anddev.org/socket_programming-t325-s30.html

EDIT:: Android WiFi examples,

Scan for Wireless Networks

Using WiFi API

SO Question Android: Is there any way to get notified when known wifi networks get in/out of range?

Community
  • 1
  • 1
user370305
  • 108,599
  • 23
  • 164
  • 151
  • Thanks, but what if I need my application to scan for available wifi networks and connect to the proper one, defined, f.e., by name? Can it be done "inside" my application? – Yury Pogrebnyak Dec 09 '11 at 09:35
  • And the last question. I get IP address via wifiInfo.getIpAddress();, IP address here is int. How can I convert it to be able to use it in socket.open(host, port)? Here host is either String or InetAddress. – Yury Pogrebnyak Dec 09 '11 at 10:59