Search code examples
javaandroidnetwork-programmingwificommunication

How to communicate between java(PC) and android under the WIFI without using modems or access-points?


After searching a lot on the web I can not find obvious answer for my question. I'm trying to send some messages using wifi between my PC and my android phone. My PC runs a java program and in this situation I have only two devices i.e a PC and an android phone. I want to make connection between these two devices without using modems or access-points. I have very little experience about networking/communication and related stuff but I already know there are two kind of communication: client-server and P2P. I have no idea which one to use in this situation.

Usually code examples or tutorials are very good ways to learn something but any idea about how can I start will also be helpful :)

thanks a lot,Soroush


Solution

  • Since you're not very experienced in this area I'm going to suggest that you create a Client-Server solution.

    The next step is to establish which end-point is going to act as the server. In most cases a mobile device would act as a client and your PC as the server, however it works both ways.

    From here you should be able to find plenty of tutorials describing how to implement this kind of solution (I've done this many times myself when I first learned this).

    Examples:

    What is a socket? - A basic walkthrough of network communication in Java, with code examples.

    Java - Networking - Another fairly straight forward tutorial.

    Android Socket Example - A more Androidy tutorial, much the same as the others.

    Hope this gets you pointing in the right direction!