开发者

socket programming with implement & interface

开发者 https://www.devze.com 2023-04-07 18:52 出处:网络
I tried this tutorial with socket programming. BUT, it is unable to send message to server when doing socket programming with implement & interface. Do you think that i can do socket programming w

I tried this tutorial with socket programming. BUT, it is unable to send message to server when doing socket programming with implement & interface. Do you think that i can do socket programming with implement & interface?? There is also no "hello" debug message.

   private class OnReadyListener implements MyCustomDialog.ReadyListener 
{
  @Override
  public void ready(String name) 
 {  
    try
     {
            DatagramSocket clientSocket = new DatagramSocket();
            String serverHostname = new String("192.168.1.12");
            InetAddress IPAddress = InetAddress.getByName(serverHostname);  
            byte[] sendData = new byte[1024];
            String sentence = "hello";
           开发者_JS百科 Log.d(TAG, "OnReadyListener ready"  + " " + sentence );
            sendData = sentence.getBytes();
            DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
            clientSocket.send(sendPacket);
            clientSocket.close();
     }
catch (UnknownHostException ex) 
     { 
ex.printStackTrace();   
     }
catch (IOException ex) 
     {
ex.printStackTrace();
     }

 }
}


here is code implemented in different form than yours, but it is pure socket programming and works well. http://thinkandroid.wordpress.com/2010/03/27/incorporating-socket-programming-into-your-applications/

0

精彩评论

暂无评论...
验证码 换一张
取 消