0

我在不关闭套接字时无法接收消息并且我使用 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();

                }

       }

我的客户安卓:

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();

我厌倦了阅读问题并且找不到答案请帮助我

4

0 回答 0