我写了一个带有0字节终止符的tcp服务器。 该安装程序可以双向使用,但是服务器在发送响应后不会关闭连接:
设置:
<int-ip:tcp-connection-factory id="MyServerConnectionFactory"
type="server"
port="8083"
serializer="MyConnectionSerializeDeserialize"
deserializer="MyConnectionSerializeDeserialize"
/>
<bean id="MyConnectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArraySingleTerminatorSerializer">
<constructor-arg type="byte" value="0" />
<property name="maxMessageSize" value="100000"/>
</bean>
<int-ip:tcp-inbound-gateway id="MyGateway"
connection-factory="MyServerConnectionFactory"
request-channel="MyIncomingServerChannel"
error-channel="errorChannel"/>
<int:channel id="MyIncomingServerChannel"/>
<int:service-activator input-channel="MyIncomingServerChannel"
ref="MyService"
method="process"/>
<bean id="MyService"
class="mypackage.MyService"/>
MyService中的代码:
public byte[] process(byte[] input) {
ByteArrayInputStream stream = new ByteArrayInputStream(input);
// process the stream
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(outstream);
pw.print("Ok");
pw.flush();
return outstream.toByteArray();
}
在发送回响应后,如何告诉框架关闭连接?
感谢
答案 0 :(得分:0)
客户端通常有责任在收到响应后关闭套接字,但是如果在连接工厂上设置了07-04 19:45:48.009 28227-28227/com.example.dell.foodapplication E/HAL: PATH3 /odm/lib64/hw/gralloc.qcom.so
PATH2 /vendor/lib64/hw/gralloc.qcom.so
PATH1 /system/lib64/hw/gralloc.qcom.so
PATH3 /odm/lib64/hw/gralloc.msm8953.so
PATH2 /vendor/lib64/hw/gralloc.msm8953.so
PATH1 /system/lib64/hw/gralloc.msm8953.so
07-04 19:45:52.731 28227-28227/com.example.dell.foodapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dell.foodapplication, PID: 28227
java.lang.OutOfMemoryError: Failed to allocate a 298598412 byte allocation with 14026592 free bytes and 171MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1272)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:308)
at android.content.res.Resources.loadDrawable(Resources.java:872)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
at android.widget.ImageView.<init>(ImageView.java:157)
at android.widget.ImageView.<init>(ImageView.java:145)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1263)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1313)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:192)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:752)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:883)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1019)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:879)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:886)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:846)
at android.view.LayoutInflater.inflate(LayoutInflater.java:522)
at android.view.LayoutInflater.inflate(LayoutInflater.java:430)
at com.example.dell.foodapplication.SelectFragment.onCreateView(SelectFragment.java:38)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2425)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2623)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2410)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2365)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2242)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1244)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1092)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:19759)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
at android.view.View.measure(View.java:19759)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6122)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:690)
at android.view.View.measure(View.java:19759)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2308)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1395)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1644)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1283)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6354)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:873)
at android.view.Choreographer.doCallbacks(Choreographer.java:685)
at android.view.Choreographer.doFrame(Choreographer.java:621)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:859)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6342)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
,则在发送响应后套接字将被关闭(通常为FIN)。 / p>