socket c-sharp发送数据而不关闭和关闭,如java中的BufferedWriter.flush

时间:2015-07-19 10:48:46

标签: android sockets closesocket

我不能接收消息虽然没有关闭套接字我使用NetworkStream但是套接字未关闭不发送数据我的代码服务器c#:

         newsocket = serversocket.AcceptSocket();
         newsocket.Send(dataSend);

         newsocket.shutdown(SocketShutdown.Send);

         c = newsocket.Receive(dataRec);

         message = Encoding.UTF8.GetString(dataRec,0,c);

          XmlSerializer xml = new XmlSerializer(typeof(Model_Users));

          using( TextReader reader=new StringReader(message))
            {
                 if (!string.IsNullOrEmpty(message.Trim()))
                {
                   users = (Model_Users)xml.Deserialize(reader);
                   dataRec = new byte[1024];
                   dataSend = Encoding.UTF8.GetBytes("THIS OK");

                   newsocket.Send(dataSend);
                   newsocket.Close();

                }

       }

我的客户端android:

socket.connect(socketAddress, 10000);
            bufferWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bufferWriter.write(getrequest);
            bufferWriter.flush();
            String rvdMsgTxt = "";
            stringBuilder = new StringBuilder();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            while ((rvdMsgTxt = bufferedReader.readLine()).equals("")) {
                stringBuilder.append(rvdMsgTxt);
                bufferedReader.mark(100);
                bufferedReader.reset();
            }

            bufferWriter.write(XMLConvertor.usersSerializeXML("user", "pass"));
            bufferWriter.flush();

我厌倦了阅读问题而没有找到答案请帮帮我

0 个答案:

没有答案