如何将多个wifi设备连接到服务器

时间:2016-02-19 06:30:36

标签: java sockets

我正在开发一个Web应用程序,其中我使用套接字连接到wifi设备。我成功地连接以及与连接的设备进行通信。现在我想将多个wifi设备连接到我的服务器。任何人都可以帮助我,下面是我的代码

public class ScheduleJob extends ServletApp implements Job{

private int port = 1717;
public static String number;
String ReceivedData = "";



public void execute(JobExecutionContext context)throws JobExecutionException {
    System.out.println("Starting ... ");

    ServerSocket Sersocket = null;
    System.out.println("Starting the socket server at port:" +port);
    boolean listeningSocket = true;
    try {
        Sersocket = new ServerSocket(port);
        System.out.println("Waiting for clients...");
    } catch (IOException e) {
        System.err.println("Could not listen on port: 1717");
    }
    try {

        while (listeningSocket) {
            Socket scokt = Sersocket.accept();
            String MachineAdd = scokt.getInetAddress().toString();
            System.out.println("Response-----" +MachineAdd);


            try{

              InputStream inStream = scokt.getInputStream();

                InputStreamReader inReader = new InputStreamReader(inStream);

                BufferedReader br = new BufferedReader(inReader);

                ReceivedData = br.readLine();
                System.out.println("ReceivedData :- "+ReceivedData);

            }catch(IOException e){
                e.printStackTrace();
            }

                //Sending the response back to the client.

                OutputStream outStream = scokt.getOutputStream();

                OutputStreamWriter outWriter = new OutputStreamWriter(outStream);
                BufferedWriter bw = new BufferedWriter(outWriter);

                bw.write("hello");
                bw.flush();

        }
        Sersocket.close();

    } catch (IOException e) {
        e.printStackTrace();
    }
  }

}

0 个答案:

没有答案