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/
精彩评论