Esempio n. 1
0
 public virtual void Stop()
 {
     Running = false;
     if (ConnectionThread != null)
     {
         ConnectionThread.Abort();
     }
 }
Esempio n. 2
0
 public void Disconnect()
 {
     if (this.ConnectionThread.ThreadState == ThreadState.Running)
     {
         ConnectionThread.Abort();
     }
     this.IsTerminated = true;
     this.Connection.Disconnect();
 }
Esempio n. 3
0
    public ThreadedTcpSrvr()
    {
        //public List<Song> musicQueue = new List<Song>();
        monocheck();
        client = new TcpListener(8009);
        client.Start();
        Console.WriteLine("Waiting for clients...");
        while (true)
        {
            while (!client.Pending())
            {
                if (musicQueue.Count > 0 && isPlaying == false)
                {
                    isPlaying = true;
                    //we'll play it
                    Song thisSong = musicQueue[0];
                    musicQueue.RemoveAt(0);
                    string currentSong = thisSong.song;
                    // ByteArrayToFile("currentsong.media", currentSong);
                    //Process mplaying = new Process();
                    mplaying.StartInfo.FileName  = "mplayer";
                    mplaying.StartInfo.Arguments = currentSong;
                    //mplaying.StartInfo.UseShellExecute = false;
                    mplaying.StartInfo.CreateNoWindow = true;
                    //mplaying.StartInfo.RedirectStandardError = true;
                    //mplaying.StartInfo.RedirectStandardOutput = true;
                    BackgroundWorkerExecProcess(mplaying);
                    System.Console.WriteLine("now playing " + thisSong.info);
                    string previous = Convert.ToString(thisSong.SID - 1);
                    //deleting file is taken care of by the destructor
                    GC.Collect();
                }
                Thread.Sleep(1000);
            }

            ConnectionThread newconnection = new ConnectionThread();
            newconnection.threadListener = this.client;
            Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
            newthread.Start();
            while (newthread.IsAlive)
            {
            }
            byte[] mySong = newconnection.song;
            if (mySong != null)
            {
                int mysongSID = GetSID();
                ByteArrayToFile(SID + ".media", mySong);
                string mySongInfo = GetSongInfo(SID + ".media", SID);
                Song   song       = new Song(mySongInfo, SID + ".media", mysongSID);
                musicQueue.Add(song);
            }
        }
    }
Esempio n. 4
0
        public void HandleRequests()
        {
            while (true) {
                while (!listener.Pending ()) {
                    Thread.Sleep (1000);
                }

                ConnectionThread newConnection = new ConnectionThread ();
                newConnection.ThreadListener = this.listener;
                Thread newThread = new Thread (new ThreadStart (newConnection.HandleConnection));
                newThread.Start ();
            }
        }
Esempio n. 5
0
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         ConnectionThread = new System.Threading.Thread(Connection_Mysql);
         ConnectionThread.Start();
     }
     else
     {
         if (ConnectionThread != null)
         {
             ConnectionThread.Abort();
         }
     }
 }
Esempio n. 6
0
    public static void Main()
    {
        TcpListener client = new TcpListener(9050);

        client.Start();

        Console.WriteLine("Waiting for clients...");
        while (true)
        {
            while (!client.Pending())
            {
                Thread.Sleep(1000);
            }
            ConnectionThread newconnection = new ConnectionThread(client);
        }
    }
 public ThreadedTcpSrvr()
 {
     client = new TcpListener(9050);
     client.Start();
     Console.WriteLine("Waiting for clients...");
     while (true)
     {
         while (!client.Pending())
         {
             Thread.Sleep(1000);
         }
         ConnectionThread newconnection = new ConnectionThread();
         newconnection.threadListener = this.client;
         Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
         newthread.Start();
     }
 }
Esempio n. 8
0
 public ThreadPoolTcpSrvr()
 {
     client = new TcpListener(9050);
     client.Start();
     Console.WriteLine("Waiting for clients...");
     while (true)
     {
         while (!client.Pending())
         {
             Thread.Sleep(1000);
         }
         var newconnection = new ConnectionThread();
         newconnection.threadListener = client;
         ThreadPool.QueueUserWorkItem(new
                                      WaitCallback(newconnection.HandleConnection));
     }
 }
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         CaseSettings     = Ewatch_MySqlMethod.CaseLoad();
         AiSettings       = Ewatch_MySqlMethod.AiLoad();
         ElectricSettings = Ewatch_MySqlMethod.ElectricLoad();
         ConnectionThread = new Thread(Connection_Mysql);
         ConnectionThread.Start();
     }
     else
     {
         if (ConnectionThread != null)
         {
             ConnectionThread.Abort();
         }
     }
 }
Esempio n. 10
0
 public void Connect()
 {
     try
     {
         if (this.Connection.Connect())
         {
             ConnectionThread.Start();
         }
         else
         {
             throw new Exception("Attempt failed");
         }
     }
     catch
     {
         throw new Exception("Connection to MSA failed");
     }
 }
 protected override void AfterMyWorkStateChanged(object sender, EventArgs e)
 {
     if (myWorkState)
     {
         CaseSettings     = ChungHsin_MySqlMethod.CaseLoad();
         ReceiveSettings  = ChungHsin_MySqlMethod.ReceiveLoad();
         DeviceConfigs    = ChungHsin_MySqlMethod.DevicesLoad();
         ConnectionThread = new Thread(Connection_Mysql);
         ConnectionThread.Start();
     }
     else
     {
         if (ConnectionThread != null)
         {
             ConnectionThread.Abort();
         }
     }
 }
            public ThreadedTcpSrvr()
            {
                ///client = new TcpListener(9050);
                client = new TcpListener(IPAddress.Any, 9050);
                client.Start();

                ///Console.WriteLine("Waiting for clients...");
                ///listBox1.Items.Add("tcp: " + "Waiting for clients...");
                while (true)
                {
                    while (!client.Pending())
                    {
                        Thread.Sleep(1000);
                    }

                    ConnectionThread newconnection = new ConnectionThread();
                    newconnection.threadListener = this.client;
                    Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
                    newthread.Start();
                }
            }
Esempio n. 13
0
        private void start_server()
        {
            IPEndPoint ipend = new IPEndPoint(IPAddress.Any, 9050);

            server = new TcpListener(ipend);
            server.Start();

            textBox1.Text = "Waiting for client. \r\n";
            Application.DoEvents();



            int threads = 0;

            while (running)
            {
                while (running && !server.Pending())
                {
                    //handle recieved messages
                    handle_msgReceived();
                    Application.DoEvents();
                }
                if (!running)
                {
                    return;
                }
                threads++;
                ConnectionThread newconnection = new ConnectionThread();
                newconnection.thread_listener = this.server;
                newconnection.thread_count    = threads;
                Thread new_thread = new Thread(new ThreadStart(newconnection.connection_handler));
                new_thread.Start();
                textBox1.AppendText("Client No:" + threads.ToString() + " started! \r\n");
                textBox1.Update();
            }
        }
Esempio n. 14
0
        /// <inheritdoc/>
        public bool Login(string defaultSchema, string user, string password, DatabaseEventCallback callback)
        {
            try {

                // Do some handshaking,
                MemoryStream bout = new MemoryStream();
                BinaryWriter output = new BinaryWriter(bout, Encoding.ASCII);

                // Write output the magic number
                output.Write(0x0ced007);
                // Write output the driver version
                Version clientVersion = ClientVersion;
                output.Write(clientVersion.Major);
                output.Write(clientVersion.Minor);
                output.Write(initialDatabase);
                byte[] arr = bout.ToArray();
                SendCommand(arr, 0, arr.Length);

                byte[] response = ReceiveCommand(0);

                int ack = ByteBuffer.ReadInt4(response, 0);
                if (ack == ProtocolConstants.Acknowledgement) {
                    // Is there anything more to Read?
                    if (response.Length > 4 && response[4] == 1) {
                        // Yes so Read the server version
                        int serverMajorVersion = ByteBuffer.ReadInt4(response, 5);
                        int serverMinorVersion = ByteBuffer.ReadInt4(response, 9);
                        serverVersion = new Version(serverMajorVersion, serverMinorVersion);
                    }

                    // Send the username and password to the server
                    // SECURITY: username/password sent as plain text.  This is okay
                    //   if we are connecting to localhost, but not good if we connecting
                    //   over the internet.  We could encrypt this, but it would probably
                    //   be better if we WriteByte the entire stream through an encyption
                    //   protocol.

                    bout = new MemoryStream();
                    output = new BinaryWriter(bout);
                    output.Write(defaultSchema);
                    output.Write(user);
                    output.Write(password);
                    arr = bout.ToArray();
                    SendCommand(arr, 0, arr.Length);

                    response = ReceiveCommand(0);
                    int result = ByteBuffer.ReadInt4(response, 0);
                    if (result == ProtocolConstants.UserAuthenticationPassed) {
                        // Set the callback,
                        databaseCallback = callback;

                        // User authentication passed so we successfully logged input now.
                        connectionThread = new ConnectionThread(this);
                        connectionThread.Start();
                        return true;

                    }
                    if (result == ProtocolConstants.UserAuthenticationFailed)
                        throw new DataException("User Authentication failed.");
                    if (result == ProtocolConstants.DatabaseNotFound)
                        throw new DataException("The database specified was not found.");

                    throw new DataException("Unexpected response.");
                }
                if (ack == ProtocolConstants.DatabaseNotFound)
                    throw new DataException("The database was not found.");

                throw new DataException("No acknowledgement received from server.");
            } catch (IOException e) {
                LogException(e);
                throw new DataException("IOException: " + e.Message);
            }
        }
Esempio n. 15
0
            public ThreadedTcpSrvr()
            {
                ///client = new TcpListener(9050);
                client = new TcpListener(IPAddress.Any, 9050);
                client.Start();

                ///Console.WriteLine("Waiting for clients...");
                ///listBox1.Items.Add("tcp: " + "Waiting for clients...");
                while (true)
                {
                    while (!client.Pending())
                    {
                        Thread.Sleep(1000);
                    }

                    ConnectionThread newconnection = new ConnectionThread();
                    newconnection.threadListener = this.client;
                    Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
                    newthread.Start();
                }
            }
Esempio n. 16
0
        private void ThreadClientConnetion()
        {
            SocketTCPHandler tcpHandler;
            ConnectionThread ctCls;

            for (; ;)
            {
                try
                {
                    if (_clientNow)
                    {
                        for (int i = _socketsCache.Values.Count - 1; i >= 0; i--)
                        {
                            tcpHandler = _socketsCache.Values.ToList()[i];
                            if (_lstclient.FindIndex(p => p._ip == tcpHandler.IP) < 0)
                            {
                                try
                                {
                                    if (tcpHandler != null)
                                    {
                                        tcpHandler.Disconnect();
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                        for (int i = 0; i < _lstclient.Count; i++)
                        {
                            if (_socketsCache.Values.ToList().FindIndex(p => (p.IP == _lstclient[i]._ip) && (p.Port.ToString() == _lstclient[i]._port)) < 0)
                            {//以前没有,就重新建立连接
                                if (LstConntionTime.FindIndex(p => p.IP == _lstclient[i]._ip) < 0)
                                {
                                    if (PingIP(_lstclient[i]._ip))
                                    {
                                        _socketClient = new SocketClientConnetion();
                                        _socketClient.OnNewSocketAccept += new NewSocketEventHandler(_socketListener_OnNewSocketAccept);
                                        ctCls = new ConnectionThread(_lstclient[i]._ip, _lstclient[i]._port, _socketClient);
                                        LstConntionTime.Add(new ConntionTime(_lstclient[i]._ip, 0));
                                    }
                                }
                            }
                        }
                    }
                    _clientNow = false;
                    for (int i = 0; i < LstConntionTime.Count; i++)
                    {
                        LstConntionTime[i].Count++;
                        if (LstConntionTime[i].Count > 30)
                        {
                            LstConntionTime.RemoveAt(i);
                            i--;
                        }
                    }
                    Thread.Sleep(500);
                }
                catch (Exception ex)
                {
                    Basic.Framework.Logging.LogHelper.Error(string.Format(" socket log: ThreadClientConnetion失败--{0}!", ex.Message));
                }
            }
        }
Esempio n. 17
0
 public PassSystem()
 {
     InitializeComponent();
     conThread = new ConnectionThread();
     conThread.Run();
 }
Esempio n. 18
0
 public WorkItemsPool(MainForm mainForm)
 {
     form = mainForm;
     this.connect = new ConnectionThread(form.getWINCCNativeProviderString(), form.getSQLOLEProviderString());
 }
Esempio n. 19
0
 public ConnectionLostArguments(string address, ConnectionThread connectionThread)
 {
     Address          = address;
     ConnectionThread = connectionThread;
 }
Esempio n. 20
0
    public ThreadedTcpSrvr()
    {
        //public List<Song> musicQueue = new List<Song>();
        monocheck();
        client = new TcpListener(8009);
        client.Start();
        Console.WriteLine("Waiting for clients...");
        while (true)
        {
            while (!client.Pending())
            {
                if (musicQueue.Count > 0 && isPlaying == false)
                {
                    isPlaying = true;
                    //we'll play it
                    Song thisSong = musicQueue[0];
                    musicQueue.RemoveAt(0);
                    string currentSong = thisSong.song;
                    // ByteArrayToFile("currentsong.media", currentSong);
                    //Process mplaying = new Process();
                    mplaying.StartInfo.FileName = "mplayer";
                    mplaying.StartInfo.Arguments = currentSong;
                    //mplaying.StartInfo.UseShellExecute = false;
                    mplaying.StartInfo.CreateNoWindow = true;
                    //mplaying.StartInfo.RedirectStandardError = true;
                    //mplaying.StartInfo.RedirectStandardOutput = true;
                    BackgroundWorkerExecProcess(mplaying);
                    System.Console.WriteLine("now playing " + thisSong.info);
                    string previous = Convert.ToString(thisSong.SID - 1);
                    //deleting file is taken care of by the destructor
                    GC.Collect();
                }
                Thread.Sleep(1000);
            }

            ConnectionThread newconnection = new ConnectionThread();
            newconnection.threadListener = this.client;
            Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection));
            newthread.Start();
            while (newthread.IsAlive)
            {
            }
            byte[] mySong = newconnection.song;
            if (mySong != null)
            {
                int mysongSID = GetSID();
                ByteArrayToFile(SID + ".media", mySong);
                string mySongInfo = GetSongInfo(SID + ".media", SID);
                Song song = new Song(mySongInfo, SID + ".media", mysongSID);
                musicQueue.Add(song);
            }
        }
    }