private void sendRequestSetup() throws IllegalStateException, SocketException, IOException {
		for (int i=0;i<2;i++) {
			Stream stream = mParameters.session.getTrack(i);
			if (stream != null) {
				String params = mParameters.transport==TRANSPORT_TCP ? 
						("TCP;interleaved="+2*i+"-"+(2*i+1)) : ("UDP;unicast;client_port="+(5000+2*i)+"-"+(5000+2*i+1)+";mode=receive");
				String request = "SETUP rtsp://"+mParameters.host+":"+mParameters.port+mParameters.path+"/trackID="+i+" RTSP/1.0\r\n" +
						"Transport: RTP/AVP/"+params+"\r\n" +
						addHeaders();

				Log.i(TAG,request.substring(0, request.indexOf("\r\n")));

				mOutputStream.write(request.getBytes("UTF-8"));
				mOutputStream.flush();
				Response response = Response.parseResponse(mBufferedReader);
				Matcher m;
				
				if (response.headers.containsKey("session")) {
					try {
						m = Response.rexegSession.matcher(response.headers.get("session"));
						m.find();
						mSessionID = m.group(1);
					} catch (Exception e) {
						throw new IOException("Invalid response from server. Session id: "+mSessionID);
					}
				}
				
				if (mParameters.transport == TRANSPORT_UDP) {
					try {
						m = Response.rexegTransport.matcher(response.headers.get("transport")); m.find();
						stream.setDestinationPorts(Integer.parseInt(m.group(3)), Integer.parseInt(m.group(4)));
						Log.d(TAG, "Setting destination ports: "+Integer.parseInt(m.group(3))+", "+Integer.parseInt(m.group(4)));
					} catch (Exception e) {
						e.printStackTrace();
						int[] ports = stream.getDestinationPorts();
						Log.d(TAG,"Server did not specify ports, using default ports: "+ports[0]+"-"+ports[1]);
					}
				} else {
					stream.setOutputStream(mOutputStream, (byte)(2*i));
				}
			}
		}
	}
Forges and sends the SETUP request
src/net/majorkernelpanic/streaming/rtsp/RtspClient.java