예제 #1
0
파일: Server.cs 프로젝트: srfoster/June
    private void HandleClientComm(object client)
    {
        TcpClient tcpClient = (TcpClient)client;
          NetworkStream clientStream = tcpClient.GetStream();

          byte[] message = new byte[4096];
          int bytesRead;

          while (true)
          {

        bytesRead = 0;

        try
        {
          //blocks until a client sends a message
          bytesRead = clientStream.Read(message, 0, 4096);
        }
        catch
        {
          //a socket error has occured
          break;
        }

        if (bytesRead == 0)
        {
          //the client has disconnected from the server
          break;
        }

        //message has successfully been received
        ASCIIEncoding encoder = new ASCIIEncoding();
        String message_string = encoder.GetString(message, 0, bytesRead);

        CallResponse call_response = new CallResponse(message_string, clientStream);
        queue.add(call_response);

          }

          tcpClient.Close();
    }
예제 #2
0
        /// <summary>
        /// Invokes the Call service.
        /// </summary>
        public IServiceResponse Call(IServiceRequest incoming)
        {
            CallResponse response = null;

            CallRequest request = (CallRequest)incoming;

            CallMethodResultCollection results = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            response = new CallResponse();

            response.ResponseHeader = ServerInstance.Call(
               request.RequestHeader,
               request.MethodsToCall,
               out results,
               out diagnosticInfos);

            response.Results         = results;
            response.DiagnosticInfos = diagnosticInfos;

            return response;
        }
예제 #3
0
 public void add(CallResponse call)
 {
     queue.Add(call);
 }
예제 #4
0
 public void add(CallResponse call)
 {
     call.setParent(this);
     queue.Add(call);
 }
예제 #5
0
        /// <summary>
        ///     发送请求
        /// </summary>
        public void DoService()
        {
            if (string.IsNullOrEmpty(this.apiKey))
            {
                this.haveDoneService = true;
                this.ocrResult       = "Error:ApiKey 不能为空 ";
                return;
            }

            this.formData["apiKey"]   = this.apiKey;
            this.formData["service"]  = this.service.ToString();
            this.formData["language"] = this.Language.ToString().ToLower();

            if (this.language == Language.Eng)
            {
                this.formData["charset"] = ((int)this.charset).ToString(CultureInfo.InvariantCulture);
            }

            if (string.IsNullOrEmpty(this.filePath) && string.IsNullOrEmpty(this.fileUrl))
            {
                this.haveDoneService = true;
                this.ocrResult       = "Error:filePath 和 fileUrl 不能同时为空 ";
                return;
            }

            if (!string.IsNullOrEmpty(this.filePath) && File.Exists(this.filePath))
            {
                if (string.IsNullOrEmpty(this.type))
                {
                    this.haveDoneService = true;
                    this.ocrResult       = "Error:上传识别验证码时 type 必须传图片的原始url ";
                    return;
                }

                if (!this.type.StartsWith("http") && !this.type.StartsWith("ftp"))
                {
                    this.haveDoneService = true;
                    this.ocrResult       = "Error:type 必须以 http/https/ftp 开头 ";
                    return;
                }

                this.formData["type"] = this.type;
                this.response         = MultiPart.MultiPost(this.apiUrl, this.formData, this.filePath);
            }
            else
            {
                if (string.IsNullOrEmpty(this.fileUrl))
                {
                    this.haveDoneService = true;
                    this.ocrResult       = "Error:filePath 和 fileUrl 不能同时为空  ";
                    return;
                }

                this.formData["url"] = this.fileUrl;
                this.response        = MultiPart.MultiPost(this.apiUrl, this.formData);
            }

            // 检查服务器响应状态
            if (this.response.OK)
            {
                this.processStatus = true;
                this.ocrResult     = this.response.Response;
            }
            else
            {
                this.ocrResult = string.Format("Error: {0}", this.response.StatusCode);
            }

            this.haveDoneService = true;
        }
예제 #6
0
파일: UserClient.cs 프로젝트: macaba/GeoVR
        private void TaskAudioPlayback(Logger logger, CancellationToken cancelToken, BlockingCollection <IMsgPackTypeName> queue)
        {
            while (!cancelToken.IsCancellationRequested)
            {
                if (queue.TryTake(out IMsgPackTypeName data, 500))
                {
                    switch (data.GetType().Name)
                    {
                    case nameof(RadioRxDto):
                    {
                        var dto = (RadioRxDto)data;
                        soundcardSampleProvider.AddOpusSamples(dto, dto.Transceivers);
                        if (logger.IsTraceEnabled)
                        {
                            logger.Trace(dto.ToDebugString());
                        }
                        break;
                    }

                    case nameof(CallRequestDto):
                    {
                        var dto = (CallRequestDto)data;
                        if (incomingCallRequest != null)
                        {
                            Connection.VoiceServerTransmitQueue.Add(new CallResponseDto()
                                {
                                    Request = dto, Event = CallResponseEvent.Busy
                                });
                        }
                        else
                        {
                            incomingCallRequest = dto;
                            soundcardSampleProvider.LandLineRing(true);
                            CallRequest?.Invoke(this, new CallRequestEventArgs()
                                {
                                    Callsign = dto.FromCallsign
                                });
                        }
                        break;
                    }

                    case nameof(CallResponseDto):
                    {
                        var dto = (CallResponseDto)data;
                        switch (dto.Event)
                        {
                        // Server events
                        case CallResponseEvent.Routed:
                            soundcardSampleProvider.LandLineRing(true);
                            CallResponse?.Invoke(this, new CallResponseEventArgs()
                                {
                                    Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Routed
                                });                                                                                                                                             //Our request was routed
                            break;

                        case CallResponseEvent.NoRoute:
                            CallResponse?.Invoke(this, new CallResponseEventArgs()
                                {
                                    Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.NoRoute
                                });                                                                                                                                             //Our request was not routed
                            break;

                        //Remote party events
                        case CallResponseEvent.Busy:
                            soundcardSampleProvider.LandLineRing(false);
                            //Play busy tone
                            CallResponse?.Invoke(this, new CallResponseEventArgs()
                                {
                                    Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Busy
                                });
                            break;

                        case CallResponseEvent.Accept:
                            soundcardSampleProvider.LandLineRing(false);
                            CallResponse?.Invoke(this, new CallResponseEventArgs()
                                {
                                    Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Accept
                                });
                            break;

                        case CallResponseEvent.Reject:
                            soundcardSampleProvider.LandLineRing(false);
                            //Play reject tone
                            CallResponse?.Invoke(this, new CallResponseEventArgs()
                                {
                                    Callsign = dto.Request.ToCallsign, Event = CallResponseEvent.Reject
                                });
                            break;
                        }
                        break;
                    }
                    }
                }
            }
        }
예제 #7
0
 public void add(CallResponse call)
 {
     queue.Add(call);
 }
예제 #8
0
    private void HandleClientComm(object client)
    {
        //Debug.Log ("Called HandleClientComm, applicationRunning is: " + applicationRunning.ToString());
          FileLogger.Log("New TCP Client accepted.");
          TcpClient tcpClient = (TcpClient)client;
          NetworkStream clientStream = tcpClient.GetStream();
          byte[] message = new byte[4096];
          int bytesRead;

          while (applicationRunning)
          {

            bytesRead = 0;
            String message_string = "";
            try
            {
                do {
                    FileLogger.Log("About to block, waiting for Java.");
                    //blocks until a client sends a message
                    bytesRead = clientStream.Read(message, 0, 4096);

                    if(bytesRead == 0){
                      throw new Exception("");
                    }

                    FileLogger.Log("Unblocked.  Got bytes from Java.");
                    ASCIIEncoding encoder = new ASCIIEncoding();
                    message_string += encoder.GetString(message, 0, bytesRead);
                } while (!message_string.EndsWith ("\n"));
            }
        catch(Exception e)
        {
          FileLogger.Log("A socket error occured or there was not data while waiting for Java: " + e.Message);

          //a socket error has occured
          break;
        }

        /*if (bytesRead == 0)
        {
          FileLogger.Log("The Java client disconnected");

          //the client has disconnected from the server
          break;
        }*/

        //message has successfully been received
        //ASCIIEncoding encoder = new ASCIIEncoding();
        //String message_string = encoder.GetString(message, 0, bytesRead);
        //} //ends while loop

        FileLogger.Log("Unity got response from Java: "+message_string);

        CallResponse call_response = new CallResponse(message_string, clientStream);
        queue.add(call_response);

          }

          FileLogger.Log("Closing TCP connection.");
          //Debug.Log ("Closing TCP connection, applicationRunning is: " + applicationRunning.ToString());
          tcpClient.Close();
    }
예제 #9
0
        /// <summary>
        /// Initializes the message with a service fault.
        /// </summary>
        public CallResponseMessage(ServiceFault ServiceFault)
        {
            this.CallResponse = new CallResponse();

            if (ServiceFault != null)
            {
                this.CallResponse.ResponseHeader = ServiceFault.ResponseHeader;
            }
        }
예제 #10
0
 /// <summary>
 /// Initializes the message with the body.
 /// </summary>
 public CallResponseMessage(CallResponse CallResponse)
 {
     this.CallResponse = CallResponse;
 }
예제 #11
0
        /// <summary cref="IServiceMessage.CreateResponse" />
        public object CreateResponse(IServiceResponse response)
        {
            CallResponse body = response as CallResponse;

            if (body == null)
            {
                body = new CallResponse();
                body.ResponseHeader = ((ServiceFault)response).ResponseHeader;
            }

            return new CallResponseMessage(body);
        }
예제 #12
0
    private void HandleClientComm(object client)
    {
        //Debug.Log ("Called HandleClientComm, applicationRunning is: " + applicationRunning.ToString());
        FileLogger.Log("New TCP Client accepted.");
        TcpClient     tcpClient    = (TcpClient)client;
        NetworkStream clientStream = tcpClient.GetStream();

        byte[] message = new byte[4096];
        int    bytesRead;

        while (applicationRunning)
        {
            bytesRead = 0;
            String message_string = "";
            try
            {
                do
                {
                    FileLogger.Log("About to block, waiting for Java.");
                    //blocks until a client sends a message
                    bytesRead = clientStream.Read(message, 0, 4096);

                    if (bytesRead == 0)
                    {
                        throw new Exception("");
                    }



                    FileLogger.Log("Unblocked.  Got bytes from Java.");
                    ASCIIEncoding encoder = new ASCIIEncoding();
                    message_string += encoder.GetString(message, 0, bytesRead);
                } while (!message_string.EndsWith("\n"));
            }
            catch (Exception e)
            {
                FileLogger.Log("A socket error occured or there was not data while waiting for Java: " + e.Message);

                //a socket error has occured
                break;
            }



            /*if (bytesRead == 0)
             * {
             *    FileLogger.Log("The Java client disconnected");
             *
             * //the client has disconnected from the server
             * break;
             * }*/

            //message has successfully been received
            //ASCIIEncoding encoder = new ASCIIEncoding();
            //String message_string = encoder.GetString(message, 0, bytesRead);
            //} //ends while loop


            FileLogger.Log("Unity got response from Java: " + message_string);

            CallResponse call_response = new CallResponse(message_string, clientStream);
            queue.add(call_response);
        }

        FileLogger.Log("Closing TCP connection.");
        //Debug.Log ("Closing TCP connection, applicationRunning is: " + applicationRunning.ToString());
        tcpClient.Close();
    }
예제 #13
0
 public void add(CallResponse call)
 {
     call.setParent(this);
     queue.Add(call);
 }