gpt4 book ai didi

android - java.net.SocketException : sendto failed: EPIPE (Broken pipe) while sending byte[] 异常

转载 作者:太空狗 更新时间:2023-10-29 15:06:48 25 4
gpt4 key购买 nike

我正在尝试上传通过安卓手机录制的视频。但是在将视频作为 byte[] 发送到服务器时出现以下错误:

  01-20 13:03:18.250: E/SaveMedia-response(4393): java.net.SocketException: sendto failed: EPIPE (Broken pipe)

这是我尝试上传视频的方式:

        SoapObject request = new SoapObject(
HelpMeConstant.WSDL_TARGET_NAMESPACE, "SaveMedia");
Log.i("SaveMedia-parameter", "Email : " + Email + ", Media : " + Media
+ "MediaType : " + MediaType + ",MediaExt : " + MediaExt);

MediaAvidance mediainfo = new MediaAvidance();
mediainfo.EmailId = Email;
mediainfo.Media = Media;
mediainfo.MediaExt = MediaExt;
mediainfo.MediaType = MediaType;

PropertyInfo pi = new PropertyInfo();
pi.setName("mediainfo");
pi.setValue(mediainfo);
pi.setType(mediainfo.getClass());

request.addProperty(pi);
/* request.addProperty("EmailId",Email);
request.addProperty("Media", Media);
request.addProperty("MediaType", MediaType);
request.addProperty("MediaExtn", MediaExt);
*/
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
Log.i("SaveMedia","Serialising..");
new MarshalBase64().register(envelope);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(
HelpMeConstant.SOAP_ADDRESS);
Object response = null;

try {
Log.i("SaveMedia","Calling service..");
httpTransport.call(HelpMeConstant.SOAP_ACTION + "SaveMedia",
envelope);
Log.i("SaveMedia","getting response..");
response = envelope.getResponse();
} catch (Exception exception) {
response = exception.toString();
}
Log.i("response", response.toString());
return response.toString();

它正在发送到如下所示的 .net Web 服务:

 [WebMethod]
public string SaveMedia(MediaAvidance avidanceinfo)
{
rs = new ResultSet();
rs = logictask.SaveMedia(avidanceinfo.EmailId,avidanceinfo.Media,avidanceinfo.MediaType,avidanceinfo.MediaExt);
return rs.isSuccessfull;
}

MediaAvidance:

public class MediaAvidance implements KvmSerializable {
public String EmailId;
public byte[] Media;
public String MediaType;
public String MediaExt;

public MediaAvidance() {
}

public MediaAvidance(String EmailID, byte[] Media, String MediaType,
String MediaExt) {

this.EmailId = EmailID;
this.Media = Media;
this.MediaType = MediaType;
this.MediaExt = MediaExt;
}

@Override
public Object getProperty(int arg0) {
switch (arg0) {
case GETEMAILID:
return EmailId;
case GETMEDIA:
return Media;
case GETMEDIATYPE:
return MediaType;
case GETMEDIAEXT:
return MediaExt;
default:
return null;
}
}

@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 4;
}

@SuppressWarnings("rawtypes")
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch (index) {
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "EmailId";
break;
case 1:
info.type = PropertyInfo.OBJECT_CLASS;
info.name = "Media";
break;
case 2:
info.type = PropertyInfo.STRING_CLASS;
info.name = "MediaType";
break;
case 3:
info.type = PropertyInfo.STRING_CLASS;
info.name = "MediaExt";
break;
default:
break;
}

}

@Override
public void setProperty(int index, Object value) {
switch (index) {
case 0:
EmailId = value.toString();
break;
case 1:
Media = (byte[]) value;
break;
case 2:
MediaType = value.toString();
break;
case 3:
MediaExt = value.toString();
break;
default:
break;
}
}
}

在服务器端 MediaAvidance 类不实现 KvmSerializable 及其方法。

我搜索了几天,并在 stackoverflow 中解决了很多问题,并了解到我正在尝试在连接关闭时编写,而且它与套接字编程有关。但是

我不知道如何保持连接(我认为可能是一种解决方案)。请帮我。

谢谢,苏拉布

最佳答案

我终于成功了。发布此解决方案希望它对像我这样的人有用。您的代码中可能有更多或以下任何问题,但我很高兴犯这 3 个错误,并从中吸取教训,这是导致视频上传出现问题的原因:

  1. 我已通过实现 KvmSerializable 在 android 中序列化了 MediaAvidance,但为了让它正常工作,您的服务器端 MediaAvidance 也必须序列化。我已经通过下面的代码解决了我遇到的 Cannot Serialize 异常:
   [Serializable]   public class MediaAvidance

您还需要将您的SoapSerializationEnvelope注册到MarshalBase64:

   envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);   new MarshalBase64().register(envelope); 
  1. 当您从 android 调用时,在 PropertyInfo 中设置与您在服务方法参数中完全相同的名称(例如:avidanceinfo),这个解决了 faultstring: 'Server was unable读取请求。异常:

    android中定义的属性名

    pi.setName("avidanceinfo");

    服务方式:

     [WebMethod] public string SaveMedia(MediaAvidance avidanceinfo)

  2. 最后你需要添加envelope.implicitTypes = true ;
    这样 HttpTransportSE 将能够识别服务器上的 MediaAvidance 类型,否则您将得到 Object reference not set to an instance of an object。当使用 xs:anyType.... 异常。

*希望这对您有所帮助。 :) *

关于android - java.net.SocketException : sendto failed: EPIPE (Broken pipe) while sending byte[] 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21228647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com