the server which is in my emulator dose never receive the server class is this :
public class Server implements Runnable { public static final String SERVERIP = "192.168.1.102"; // 'Within' the emulator! public static final int SERVERPORT = 2060; public void run() { Log.e("receive","new socket"); DatagramSocket socket = null; try { socket = new DatagramSocket(SERVERPORT); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } byte[] buf = new byte[1024]; Log.e("receive","new packet"); DatagramPacket packet = new DatagramPacket(buf, buf.length); try { socket.setSoTimeout(10000); } catch (SocketException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Log.e("receive","receive !"); try { socket.receive(packet); Log.e("receive",new String(packet.getData())); }catch (SocketTimeoutException e){Log.e("receive","time out");} catch (IOException e) {Log.e("receive","error 1"); // TODO Auto-generated catch block e.printStackTrace(); } Log.e("receive","end"); } }
and the sender is :
public class UDPClient { public static void main(String args[]) throws IOException { InetAddress ip=InetAddress.getByName("192.168.1.102"); DatagramSocket socket=new DatagramSocket(); byte[] outData = ("helloooo").getBytes(); DatagramPacket out = new DatagramPacket(outData,outData.length,ip ,2060); socket.send(out); System.out.println("Send >>> "); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)