i am developing an application which can send camera frames and audio recorded from one android mobile to another
using UDP with DatagramPacket class
I've managed to send the recorded audio and playing it on the other side
also I've managed to capture Camera Frames through
Camera.PreviewCallback previewCalBac = new PreviewCallback() {
#Override
public void onPreviewFrame(byte[] data, Camera camera) {
if (data != null) {
// mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Log.d("CAMERA", "CHANGED" + data.length);
startStreamingVideo(data);
}
}
};
and the sending operation is like this
private void startStreamingVideo(byte[] data) {
Log.d(VIDEO_CLIENT_TAG, "Starting the video stream");
if(data!=null){
currentlySendingVideo = true;
startVStreaming(data);}
else{
Log.d(VIDEO_CLIENT_TAG, "NULL DATA");
}
}
private void startVStreaming(final byte[] data) {
Log.d(VIDEO_CLIENT_TAG,
"Starting the background thread to stream the video data");
Thread streamThread = new Thread(new Runnable() {
#Override
public void run() {
try {
Log.d(VIDEO_CLIENT_TAG, "Creating the datagram socket");
DatagramSocket socket = new DatagramSocket();
Log.d(VIDEO_CLIENT_TAG, "Creating the buffer of size "+ data.length);
byte[] buffer = new byte[4096];
Log.d(VIDEO_CLIENT_TAG, "Connecting to "+ ipAddress.getText().toString() + ":" + VPORT);
final InetAddress serverAddress = InetAddress.getByName(ipAddress.getText().toString());
Log.d(VIDEO_CLIENT_TAG, "Connected to "+ ipAddress.getText().toString() + ":" + VPORT);
Log.d(VIDEO_CLIENT_TAG,"Creating the reuseable DatagramPacket");
DatagramPacket packet;
Log.d(VIDEO_CLIENT_TAG, "Creating the VideoRecord");
// recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,RECORDING_RATE, CHANNEL, FORMAT, data.length);
// Log.d(VIDEO_CLIENT_TAG, "VideoRecord recording...");
// recorder.startRecording();
while (currentlySendingVideo == true) {
// read the data into the buffer
Log.d(VIDEO_CLIENT_TAG, "Here0");
// int read = recorder.read(data, 0, data.length);
Log.d(VIDEO_CLIENT_TAG, "Here");
// place contents of buffer into the packet
packet = new DatagramPacket(data, 4096,serverAddress, VPORT);
Log.d(VIDEO_CLIENT_TAG, "Here1");
// send the packet
socket.send(packet);
Log.d(VIDEO_CLIENT_TAG, "Here2");
}
Log.d(VIDEO_CLIENT_TAG, "VideoRecord finished recording");
} catch (Exception e) {
Log.e(VIDEO_CLIENT_TAG, "HERE Exception: " + e);
}
}
});
// start the thread
streamThread.start();
}
the server side i can get to know that i am receiving the packets
the problem is that the bitmap image byte[] is too big to be sent
i need to scale it to the best size so i can transfer it and receive it with the least amount of wasted bytes.
any solution to this problem?
Not with UDP, no. You need a protocol on top of UDP to handle messages>64K. There is no alternative.
Related
i'm trying to decode data that i send through TCP.
I successfully managed to fill in the decoder.
But when i try to get the output to render it on a surfaceView. i get this error:
dequeueBuffer failed: BAD_VALUE(-22)
Also, outputBufferIdde is always equal to -1 (try again later)
this is my code :
try {
serverSocket = new ServerSocket(2968);
Log.d(TAG,"server accept");
Socket client = serverSocket.accept();
InputStream inputStream = client.getInputStream();
inputBuffersde = decodec.getInputBuffers();
Log.d(TAG, "encodeDecode 1");
DecoderRunnable decoderRunnable=new DecoderRunnable(decodec,infode);
new Thread(decoderRunnable).start();
while (true) {
dataSizes=new byte[4];
inputStream.read(dataSizes,0,4);
dataSize=ByteBuffer.wrap(dataSizes).getInt();
Log.d(TAG,"size: "+dataSize);
totalLen=0;
data= new byte[dataSize];
for(;totalLen<dataSize;) {
len=inputStream.read(data, totalLen, dataSize-totalLen);
totalLen+=len;
Log.d(TAG,"totalLen: "+totalLen+" ,len: "+len);
}
int inputBufferIdde = decodec.dequeueInputBuffer(5000);
Log.d(TAG,"inputBufferIdde: "+inputBufferIdde);
if (inputBufferIdde >= 0) {
Log.d(TAG,"inputBufferIdde: "+inputBufferIdde);
inputBuffersde[inputBufferIdde].clear();
inputBuffersde[inputBufferIdde].rewind();
inputBuffersde[inputBufferIdde].put(data);
decodec.queueInputBuffer(inputBufferIdde, 0, inputBuffersde[inputBufferIdde].position(), System.nanoTime(), 0);
}
}
} catch(IOException e){
e.printStackTrace();
}
DecoderRunnable looks like this :
public DecoderRunnable(MediaCodec decodec, MediaCodec.BufferInfo infode) {
this.decodec = decodec;
this.infode = infode;
}
#Override
public void run() {
while(true){
int outputBufferIdde = decodec.dequeueOutputBuffer(infode, 5000);
Log.d(TAG, "outputBufferIdde : " + outputBufferIdde);
if (outputBufferIdde >= 0) {
Log.d(TAG, "encodeDecode 7");
decodec.releaseOutputBuffer(outputBufferIdde, true);
}
}
}
Can someone help me?
Intend:
I´m trying to develop a single-purpose app, which you can not exit. It should run on a phone as an "operating system". This phone will be used for further purposes. The app will not be in the play store and also you can´t leave it so I need to update it otherwise if I have newer versions. For this purpose I´ve written another app which you could call the "updater-app". I want to do this update via Bluetooth. I already prepared everything and it´s ready for file transfer. The phones can connect by an InsecureRfcommSocket. I also managed to select the .apk file which I want to send with a chooser on the updater-app and I´m converting the uri into bytes in this Code:
sendUpdateButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mBtService != null) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("application/vnd.android.package-archive");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Choose .apk"), FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(), "No File-Explorer found", Toast.LENGTH_SHORT).show();
}
}
}
});
and the onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == FILE_SELECT_CODE && resultCode == RESULT_OK && data != null) {
Uri selectedFile = data.getData();
try {
byte[] sendingByte = readBytes(selectedFile);
mBtService.send(sendingByte);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), R.string.transmissionFailed, Toast.LENGTH_SHORT).show();
}
}
}
the readBytes function:
public byte[] readBytes(Uri uri) throws IOException {
InputStream inputStream = getContentResolver().openInputStream(uri);
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
return byteBuffer.toByteArray();
}
with the mBtService.send(sendingByte) row the following function is called in the ConnectedThread:
public void send(byte[] selectedFile) {
try {
mmOutStream.write(selectedFile);
} catch (IOException e) {
e.printStackTrace();
}
}
Problem:
In the receiver phone I´ve got no idea how to receive the bytes and convert it back to a file/uri (no idea yet) .apk and save it to my phone to execute it with another button which is not part of this question.
Question:
So my question is what to to in the code of the receiver phone app to manage finish my intend? If I missed to post any relevant code I´m sorry and will add it on your Request. As I have to program this both apps for my studies I´m thankful for any help.
I found a Solution to save the received Bytes to a ByteArray and then save it to a File. In my Bluetooth ConnectedThread I have the following run() method:
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int len;
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
try {
while ((len = mmInStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
mHandler.obtainMessage(Constants.MESSAGE_READ, len, -1, byteBuffer.toByteArray())
.sendToTarget();
}
} catch (IOException e) {
e.printStackTrace();
connectionLost();
}
}
And in my Activity I have the following Handler MESSAGE_READ:
private final Handler mHandler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case Constants.MESSAGE_STATE_CHANGE:
...
break;
case Constants.MESSAGE_READ:
byte[] buffer = (byte[]) msg.obj;
try {
String filePath = Environment.getExternalStorageDirectory() + "/download/app.apk";
File file = new File(filePath);
file.getParentFile().mkdirs();
if (file.exists()) {
file.delete();
file.createNewFile();
}
else
file.createNewFile();
BufferedOutputStream objectOut = new BufferedOutputStream(new FileOutputStream(file));
objectOut.write(buffer);
objectOut.close();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
};
With this Code the .apk is saved to the regular Download folder as "app.apk".
Hope this is helpful for anyone.
I am using android autobahn websocket for establish connection between android and python tornado socket server .
Below is the autobahn websocket code which am using in android .
public void start() {
final String wsuri = ip;
try {
mConnection.connect(wsuri, new WebSocketHandler() {
#Override
public void onOpen() {
Log.d(TAG, "Connected to " + wsuri);
}
#Override
public void onTextMessage(String payload) {
Log.d(TAG, "Got echo: " + payload);
try{
InputStream stream = new ByteArrayInputStream(Base64.decode((payload).getBytes(), Base64.DEFAULT));
Bitmap bitmap = BitmapFactory.decodeStream(stream);
image.setImageBitmap(bitmap);
} catch (Exception e) {
Log.d("got exception:", e.toString());
}
}
#Override
public void onClose(int code, String reason) {
Log.d(TAG, "Connection lost.");
Toast.makeText(Project12.this, "Server is Closed", Toast.LENGTH_SHORT).show();
}
});
} catch (WebSocketException e) {
Log.d(TAG, e.toString());
Toast.makeText(Project12.this, "Given IP Adress is not available", Toast.LENGTH_SHORT).show();
return;
}
}
All messages are receiving in public void onTextMessage(Object payload) method.
Problem is that when am sending images less than 128 kb from python socket server, am able to receive it .But when am sending images having size more than 128 kb it shows error which mention below.
WebSocketException (de.tavendo.autobahn.WebSocketException: frame payload too large)
So how can i increase frame payload size.
you need to use WebSocketOptions like this:
WebSocketOptions options = new WebSocketOptions();
options.setMaxMessagePayloadSize(1000000); //max size of message
options.setMaxFramePayloadSize(1000000); //max size of frame
mConnection.connect(wsuri, new WebSocketHandler() {},options);
I am streaming my phone's microphone input data to the PC using UDP with Android App as Client and a Python Server. It works fine, no errors.
But even after tweaking a lot, I get a lot of noise on my server side.
I'd like to know if there is anything wrong with my code or it's normal?
Client:
public class MainActivity extends Activity {
private Button startButton,stopButton;
public byte[] buffer;
public static DatagramSocket socket;
private int port=8080;
AudioRecord recorder;
private int sampleRate = 44100 ; // 44100 for music
private int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
private int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
private boolean status = true;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startButton = (Button) findViewById (R.id.start_button);
stopButton = (Button) findViewById (R.id.stop_button);
startButton.setOnClickListener (startListener);
stopButton.setOnClickListener (stopListener);
}
private final OnClickListener stopListener = new OnClickListener() {
#Override
public void onClick(View arg0) {
status = false;
recorder.release();
Log.d("VS","Recorder released");
}
};
private final OnClickListener startListener = new OnClickListener() {
#Override
public void onClick(View arg0) {
status = true;
startStreaming();
}
};
public void startStreaming() {
Thread streamThread = new Thread(new Runnable() {
#Override
public void run() {
try {
DatagramSocket socket = new DatagramSocket();
Log.d("VS", "Socket Created");
byte[] buffer = new byte[minBufSize];
Log.d("VS","Buffer created of size " + minBufSize);
DatagramPacket packet;
Log.d("VS", "Address retrieved");
final InetAddress destination = InetAddress.getByName("10.0.0.2");
Log.d("VS", "Address retrieved");
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,sampleRate,channelConfig,audioFormat,minBufSize*10);
Log.d("VS", "Recorder initialized");
recorder.startRecording();
while(status == true) {
//reading data from MIC into buffer
minBufSize = recorder.read(buffer, 0, buffer.length);
//putting buffer in the packet
packet = new DatagramPacket (buffer,buffer.length,destination,port);
socket.send(packet);
System.out.println("MinBufferSize: " +minBufSize);
}
} catch(UnknownHostException e) {
Log.e("VS", "UnknownHostException",e);
} catch (IOException e) {
e.printStackTrace();
Log.e("VS", ""+ e);
}
}
});
streamThread.start();
}
}
Server:
import pyaudio
import socket
from threading import Thread
import numpy as np
from matplotlib import pyplot as plt
frames = []
def udpStream(CHUNK):
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp.bind(("0.0.0.0", 8080))
while True:
# soundData, addr = udp.recvfrom(CHUNK)
soundData, addr = udp.recvfrom(CHUNK * CHANNELS * 2)
frames.append(soundData)
print numpydata
plt.plot(numpydata)
plt.show()
udp.close()
def play(stream, CHUNK):
BUFFER = 10
while True:
if len(frames) == BUFFER:
while True:
try:
stream.write(frames.pop(0), CHUNK)
except:
pass
if __name__ == "__main__":
FORMAT = pyaudio.paInt16
CHUNK = 1024
CHANNELS = 2
RATE = 44100
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels = CHANNELS,
rate = RATE,
output = True,
input=True,
frames_per_buffer = CHUNK,
)
Ts = Thread(target = udpStream, args=(CHUNK,))
Tp = Thread(target = play, args=(stream, CHUNK,))
Ts.setDaemon(True)
Tp.setDaemon(True)
Ts.start()
Tp.start()
Ts.join()
Tp.join()
I was able to use your Android app code with a much simpler server setup and it works fairly well.
import pyaudio
import socket
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 4096
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp.bind(("0.0.0.0", 5001))
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, output=True, frames_per_buffer=CHUNK)
try:
while True:
data, addr = udp.recvfrom(CHUNK)
stream.write(data)
except KeyboardInterrupt:
pass
print('Shutting down')
udp.close()
stream.close()
audio.terminate()
Your code includes no audio safety buffer to handle jitter in the UDP network transmission rate. UDP over WiFi is neither a media synchronous nor a reliable transport, so some fraction of a second of pre-filled safety buffer, plus something to handle dropouts smoothly, may be required.
I want to connect the VPN in my Application.
I download the demo from https://github.com/guardianproject/OrbotVPN
package org.torproject.android.vpn;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.VpnService;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.widget.Toast;
import com.runjva.sourceforge.jsocks.protocol.ProxyServer;
import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
public class OrbotVpnService extends VpnService implements Handler.Callback, Runnable {
private static final String TAG = "OrbotVpnService";
private String mServerAddress = "192.xx.xx.xx";
private int mServerPort = xxxx;
private PendingIntent mConfigureIntent;
private Handler mHandler;
private Thread mThread;
private String mSessionName = "OrbotVPN";
private ParcelFileDescriptor mInterface;
private int mSocksProxyPort = 9999;
private boolean mKeepRunning = true;
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
// The handler is only used to show messages.
if (mHandler == null) {
mHandler = new Handler(this);
}
// Stop the previous session by interrupting the thread.
if (mThread != null) {
mThread.interrupt();
}
// Start a new session by creating a new thread.
mThread = new Thread(this, "OrbotVpnThread");
mThread.start();
startSocksBypass ();
return START_STICKY;
}
private void startSocksBypass ()
{
Thread thread = new Thread ()
{
public void run ()
{
try {
final ProxyServer server = new ProxyServer(new ServerAuthenticatorNone(null, null));
server.setVpnService(OrbotVpnService.this);
server.start(9999, 5, InetAddress.getLocalHost());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
};
thread.start();
}
#Override
public void onDestroy() {
if (mThread != null) {
mKeepRunning = false;
mThread.interrupt();
}
}
#Override
public boolean handleMessage(Message message) {
if (message != null) {
Toast.makeText(this, message.what, Toast.LENGTH_SHORT).show();
}
return true;
}
#Override
public synchronized void run() {
try {
Log.i(TAG, "Starting");
// If anything needs to be obtained using the network, get it now.
// This greatly reduces the complexity of seamless handover, which
// tries to recreate the tunnel without shutting down everything.
// In this demo, all we need to know is the server address.
InetSocketAddress server = new InetSocketAddress(
mServerAddress, mServerPort);
mHandler.sendEmptyMessage(R.string.connecting);
run(server);
} catch (Exception e) {
Log.e(TAG, "Got " + e.toString());
try {
mInterface.close();
} catch (Exception e2) {
// ignore
}
mHandler.sendEmptyMessage(R.string.disconnected);
} finally {
}
}
/*
#Override
public synchronized void run() {
try {
Log.i(TAG, "Starting");
// If anything needs to be obtained using the network, get it now.
// This greatly reduces the complexity of seamless handover, which
// tries to recreate the tunnel without shutting down everything.
// In this demo, all we need to know is the server address.
InetSocketAddress server = new InetSocketAddress(
mServerAddress, mServerPort);
// We try to create the tunnel for several times. The better way
// is to work with ConnectivityManager, such as trying only when
// the network is avaiable. Here we just use a counter to keep
// things simple.
for (int attempt = 0; attempt < 10; ++attempt) {
mHandler.sendEmptyMessage(R.string.connecting);
// Reset the counter if we were connected.
if (run(server)) {
attempt = 0;
}
// Sleep for a while. This also checks if we got interrupted.
Thread.sleep(3000);
}
Log.i(TAG, "Giving up");
} catch (Exception e) {
Log.e(TAG, "Got " + e.toString());
} finally {
try {
mInterface.close();
} catch (Exception e) {
// ignore
}
mInterface = null;
mHandler.sendEmptyMessage(R.string.disconnected);
Log.i(TAG, "Exiting");
}
}*/
DatagramChannel mTunnel = null;
private boolean run(InetSocketAddress server) throws Exception {
boolean connected = false;
// Create a DatagramChannel as the VPN tunnel.
mTunnel = DatagramChannel.open();
DatagramSocket s = mTunnel.socket();
// Protect the tunnel before connecting to avoid loopback.
if (!protect(s)) {
throw new IllegalStateException("Cannot protect the tunnel");
}
mTunnel.connect(server);
// For simplicity, we use the same thread for both reading and
// writing. Here we put the tunnel into non-blocking mode.
mTunnel.configureBlocking(false);
// Authenticate and configure the virtual network interface.
handshake();
// Now we are connected. Set the flag and show the message.
connected = true;
mHandler.sendEmptyMessage(R.string.connected);
new Thread ()
{
public void run ()
{
// Allocate the buffer for a single packet.
ByteBuffer packet = ByteBuffer.allocate(32767);
// Packets to be sent are queued in this input stream.
FileInputStream in = new FileInputStream(mInterface.getFileDescriptor());
// Packets received need to be written to this output stream.
FileOutputStream out = new FileOutputStream(mInterface.getFileDescriptor());
// We use a timer to determine the status of the tunnel. It
// works on both sides. A positive value means sending, and
// any other means receiving. We start with receiving.
int timer = 0;
Log.d(TAG,"tunnel open:" + mTunnel.isOpen() + " connected:" + mTunnel.isConnected());
// We keep forwarding packets till something goes wrong.
while (true) {
try
{
// Assume that we did not make any progress in this iteration.
boolean idle = true;
// Read the outgoing packet from the input stream.
int length = in.read(packet.array());
if (length > 0) {
Log.d(TAG,"got outgoing packet; length=" + length);
// Write the outgoing packet to the tunnel.
packet.limit(length);
mTunnel.write(packet);
packet.clear();
// There might be more outgoing packets.
idle = false;
// If we were receiving, switch to sending.
if (timer < 1) {
timer = 1;
}
}
// Read the incoming packet from the mTunnel.
length = mTunnel.read(packet);
if (length > 0) {
Log.d(TAG,"got inbound packet; length=" + length);
// Write the incoming packet to the output stream.
out.write(packet.array(), 0, length);
packet.clear();
// There might be more incoming packets.
idle = false;
// If we were sending, switch to receiving.
if (timer > 0) {
timer = 0;
}
}
// If we are idle or waiting for the network, sleep for a
// fraction of time to avoid busy looping.
if (idle) {
Thread.sleep(100);
// Increase the timer. This is inaccurate but good enough,
// since everything is operated in non-blocking mode.
timer += (timer > 0) ? 100 : -100;
// We are receiving for a long time but not sending.
if (timer < -15000) {
// Switch to sending.
timer = 1;
}
// We are sending for a long time but not receiving.
if (timer > 20000) {
//throw new IllegalStateException("Timed out");
//Log.d(TAG,"receiving timed out? timer=" + timer);
}
}
}
catch (Exception e)
{
Log.d(TAG,"error in tunnel",e);
}
}
}
}.start();
return connected;
}
private void handshake() throws Exception {
if (mInterface == null)
{
Builder builder = new Builder();
builder.setMtu(1500);
builder.addAddress("10.0.2.0",24);
builder.setSession("OrbotVPN");
builder.addRoute("0.0.0.0",0);
builder.addDnsServer("8.8.8.8");
// builder.addDnsServer("127.0.0.1:5400");
// Close the old interface since the parameters have been changed.
try {
mInterface.close();
} catch (Exception e) {
// ignore
}
// Create a new interface using the builder and save the parameters.
mInterface = builder.setSession(mSessionName)
.setConfigureIntent(mConfigureIntent)
.establish();
}
}
private void debugPacket(ByteBuffer packet)
{
/*
for(int i = 0; i < length; ++i)
{
byte buffer = packet.get();
Log.d(TAG, "byte:"+buffer);
}*/
int buffer = packet.get();
int version;
int headerlength;
version = buffer >> 4;
headerlength = buffer & 0x0F;
headerlength *= 4;
Log.d(TAG, "IP Version:"+version);
Log.d(TAG, "Header Length:"+headerlength);
String status = "";
status += "Header Length:"+headerlength;
buffer = packet.get(); //DSCP + EN
buffer = packet.getChar(); //Total Length
Log.d(TAG, "Total Length:"+buffer);
buffer = packet.getChar(); //Identification
buffer = packet.getChar(); //Flags + Fragment Offset
buffer = packet.get(); //Time to Live
buffer = packet.get(); //Protocol
Log.d(TAG, "Protocol:"+buffer);
status += " Protocol:"+buffer;
buffer = packet.getChar(); //Header checksum
String sourceIP = "";
buffer = packet.get(); //Source IP 1st Octet
sourceIP += buffer;
sourceIP += ".";
buffer = packet.get(); //Source IP 2nd Octet
sourceIP += buffer;
sourceIP += ".";
buffer = packet.get(); //Source IP 3rd Octet
sourceIP += buffer;
sourceIP += ".";
buffer = packet.get(); //Source IP 4th Octet
sourceIP += buffer;
Log.d(TAG, "Source IP:"+sourceIP);
status += " Source IP:"+sourceIP;
String destIP = "";
buffer = packet.get(); //Destination IP 1st Octet
destIP += buffer;
destIP += ".";
buffer = packet.get(); //Destination IP 2nd Octet
destIP += buffer;
destIP += ".";
buffer = packet.get(); //Destination IP 3rd Octet
destIP += buffer;
destIP += ".";
buffer = packet.get(); //Destination IP 4th Octet
destIP += buffer;
Log.d(TAG, "Destination IP:"+destIP);
status += " Destination IP:"+destIP;
/*
msgObj = mHandler.obtainMessage();
msgObj.obj = status;
mHandler.sendMessage(msgObj);
*/
//Log.d(TAG, "version:"+packet.getInt());
//Log.d(TAG, "version:"+packet.getInt());
//Log.d(TAG, "version:"+packet.getInt());
}
}
It also connected with VPN and show the key symbol on top of the bar, but dont found any server entry in my server Interfaces.Same server I register in mobile network it Connected and I found the Server entry in my server Interfaces.
Is there any server Implementation require?
Am I wrong in above VPN service or I make the mistake in it?
Is there other way for connecting the VPN using the Username,password and server Id?
Try this :
void startVPN(String name) {
Intent i=new Intent("doenter.onevpn.ACTION_CONNECT");
i.putExtra("name",name);
i.putExtra("force", true);
i.putExtra("force_same", false);
startActivity(i);
}
void restartVPN(String name) {
Intent i=new Intent("doenter.onevpn.ACTION_CONNECT");
i.putExtra("name",name);
i.putExtra("force", true);
i.putExtra("force_same", true);
startActivity(i);
}
void stopVPN() {
Intent i=new Intent("doenter.onevpn.ACTION_DISCONNECT");
// Stops any VPN regardless of name
startActivity(i);
}