我需要您的帮助,我尝试创建客户端-服务器应用程序。客户端是安卓手机,服务器是PC(C#)。我想要实时(尽可能)传输相机预览。我想我必须在 C# UDP 和 java DatagramSocket 中使用。我添加了从相机获取预览的功能,我尝试将字节数组发送到服务器,但它不起作用。也许你对我有一些解决方案,这是我的代码
private Camera.PreviewCallback mPrevCallback = new Camera.PreviewCallback()
{
public void onPreviewFrame( byte[] data, Camera Cam ) {
Log.e("CombineTestActivity", "Preview started");
Log.e("CombineTestActivity", "Data length = "
+ data.length );
try
{
InetAddress serverAddr = null;
try {
serverAddr = InetAddress.getByName("192.168.0.102");
} catch (UnknownHostException e) {
e.printStackTrace();
}
DatagramPacket packet = new DatagramPacket(data, data.length, serverAddr, 9050);
updatetrack("Client: Sending '" + new String(data) + "'\n");
Log.e("Client ", "C: Sending");
try {
socket.send(packet);
} catch (IOException e) {
e.printStackTrace();
}
}
};