Beispiel #1
0
        private void    TcpCsSocketConnectToServer(SecureTunnel st)
        {
            Debug.Log("CsSocketTcp Creating XboxOneEndPoint...");
            if (this.OurTcpCsSocketConnection.State != SecureTunnelState.Ready)
            {
                Debug.Log("CsSocketTcp Aborting - SecureTunnel is not Ready.");
                return;
            }

            this.OurTcpCsSocketServerEndpoint = new XboxOneEndPoint(st);
            this.TcpSendMessageToServer(this.OurTcpCsSocketServerEndpoint);
        }
Beispiel #2
0
        private void    TcpSendMessageToServer(XboxOneEndPoint ServerEndpoint)
        {
            // If you call this function again too quickly, the local port we bound to may not have been freed up yet, and you'll get an exception (10048)
            try
            {
                TcpClient tcpClient = new TcpClient();
                tcpClient.Client = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
                tcpClient.Client.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0);   // Mandatory, as discussed above
                tcpClient.Client.Bind(new IPEndPoint(IPAddress.IPv6Any, this.port));                 //
                tcpClient.Client.Connect(ServerEndpoint);

                this.clientAvailable = new Client(tcpClient);

                Debug.Log("Client is available. Please click Connect again to start the transmission.");

                //// Get the stream to the server
                //NetworkStream stream = new NetworkStream(client);

                //// Read the server greeting
                //Byte[]data = new Byte[256];
                //String responseData = String.Empty;
                //Int32 bytes = stream.Read(data, 0, data.Length);
                //responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

                //// Write our response to the server
                //Byte[] OutData = System.Text.Encoding.ASCII.GetBytes("TCP Client Response");
                //stream.Write(OutData, 0, OutData.Length);

                //// Disconnect
                //stream.Close();
                //client.Shutdown(SocketShutdown.Both);
                //client.Disconnect(true);
                //client.Close();
                //Debug.Log("Sent message to server, received response: " + responseData);
            }
            catch (ArgumentNullException e)
            {
                Debug.Log("ArgumentNullException: " + e);
            }
            catch (SocketException e)
            {
                Debug.Log("SocketException: " + e.ErrorCode + "," + e.Message);
            }
            catch (Exception e)
            {
                Debug.Log("Exception: " + e);
            }
        }