如何从LAN端口读取数据并在浏览器小程序上显示? sock.receive(进入);

时间:2017-06-09 08:58:06

标签: java swing sockets applet datagram

它最适合sock.receive(incoming);在我的浏览器下的小程序。

sock.receive(incoming);此行之后它被卡住了。什么都没有显示。

或者没有错误或异常,即使它远离此行。

请帮帮我。先感谢您 :) 对不起,我的英语不好

这是我的代码。

 while(true)
                    {
            System.out.println("Under While loop...");
                if(incoming != null)
                {
                    System.out.println("Data is not blank..." + incoming );
                }
                else
                {
                    System.out.println("Data is blank..." + incoming );
                }
              sock.receive(incoming);
            System.out.println("Hello..");
                        byte[] data = incoming.getData();
                if(data != null)
                {
                    System.out.println("Data is not blank...");
                }
                else
                {
                    System.out.println("Data is blank...");
                }
                        String s = new String(data, 0, incoming.getLength());


                        //echo the details of incoming data - client ip : client port - client message
                        System.out.println(incoming.getAddress().getHostAddress() + " : " + incoming.getPort() + " : " + s);

              if(s != "" )
             {

                String R = incoming.getAddress().getHostAddress() + " : " + incoming.getPort() + " : " + s;
                //lblResultTest.setText(R);
                String[] words = s.split("&");

                txtResult.setText(words[2]);
                this.getAppletContext().showDocument( this.getDocumentBase() );


             }  
                        //s = "OK : " + s;
                        //DatagramPacket dp = new DatagramPacket(s.getBytes() , s.getBytes().length , incoming.getAddress() , incoming.getPort());
                        //sock.send(dp);
                        }
        }
        catch(InterruptedException ex) 
        {
            Thread.currentThread().interrupt();
        }

        }

0 个答案:

没有答案