Esempio n. 1
0
        protected static void StartSending(Socket socket, Package package)
        {
            var             data      = package.ToByteArray();
            SocketContainer container = new SocketContainer(socket, data);

            socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(_OnSendingCallback), container);
        }
Esempio n. 2
0
        /// <summary>
        /// Sends a package
        /// </summary>
        /// <param name="package">package to send</param>
        /// <param name="clientAddress">destination address of the package</param>
        internal static bool SendPackage(Package package, string clientAddress)
        {
            SProgram.WritePackageSendInfo(package, clientAddress);
            TcpClient client = null;

            byte[] buffer = package.ToByteArray();

            try
            {
                client = new TcpClient(clientAddress, ConnectionConfig.clientPort);
                NetworkStream stream = client.GetStream();
                stream.Write(buffer, 0, buffer.Length);
                stream.Close();
                client.Close();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }