Code example for Socket

Methods: getPort

0
	public void onClick(DialogInterface dialog, int which) {
		try { 
			int localPort = Integer.parseInt(DatabaseSQLiteQueryEngine
					.selectUser((String) Session.get("username"))
					.getPhoneNumber()) + 1111; 
			Socket clientSocket = new Socket(InetAddress.getByName("10.0.2.2"),
					addr, InetAddress.getByName("10.0.2.15"), localPort);
			Integer port = clientSocket.getPort();
 
			connectedClients.put(port, clientSocket);
			Intent i = new Intent(context, IMActivity.class);
			i.putExtra("from", "IMClickListener");
			i.putExtra("port", port);
			context.startActivity(i);
		} catch (UnknownHostException e) {
			Log.e("IMClickListener", "Unable to create socket. Stack trace:");
			e.printStackTrace();
		} catch (IOException e) {
			Log.e("IMClickListener", "Unable to create socket. Stack trace:");
			e.printStackTrace();
		}