public User(String user, String address, int port) { handler = new SpreadConnection.MessageHandler( messageReceived ); // Establish the spread connection. /////////////////////////////////// try { connection = new SpreadConnection(); connection.Connect(address, port, user, false, true); } catch(SpreadException e) { Console.Error.WriteLine("There was an error connecting to the daemon."); Console.WriteLine(e); Environment.Exit(1); } catch(Exception e) { Console.Error.WriteLine("Can't find the daemon " + address); Console.WriteLine(e); Environment.Exit(1); } rt = new recThread( connection ); Thread rtt = new Thread(new ThreadStart(rt.run)); rtt.Start(); // Show the menu. ///////////////// PrintMenu(); // Get a user command. ////////////////////// while(true) { UserCommand(); } }
private void connect(string pGroup) { // Establish the spread connection. try { connection = new SpreadConnection(); connection.Connect(address, port, userName, false, true); } catch (SpreadException _ex) { T.LogCritical("There was an error connecting to the daemon: " + _ex); Environment.Exit(1); } catch (Exception _ex) { T.LogCritical("Can't find the daemon " + address + " Exception: " + _ex); Environment.Exit(1); } // start receiving thread rt = new RecThread(connection); Thread rtt = new Thread(new ThreadStart(rt.Run)); rtt.Start(); // start listener regularMessageHandler = new SpreadConnection.MessageHandler(regularMsgReceived); connection.OnRegularMessage += regularMessageHandler; membershipMessageHandler += new SpreadConnection.MessageHandler(membershipMsgReceived); connection.OnMembershipMessage += membershipMessageHandler; lock (rt) { rt.threadSuspended = true; } listening = true; T.LogStatus("Listening: " + listening); // join group group = new SpreadGroup(); group.Join(connection, pGroup); T.LogStatus("Joined: " + group + "."); }
private void button1_Click(object sender, EventArgs e) { string address = null; int port = 0; string user = textBox1.Text; handler = new SpreadConnection.MessageHandler(messageReceived); try { connection = new SpreadConnection(); connection.Connect(address, port, user, false, true); rtt = new Thread(new ThreadStart(this.run)); rtt.Start(); } catch (SpreadException ex) { MessageBox.Show("There was an error connecting to the daemon."+ex.Message); } catch (Exception ex) { MessageBox.Show("Can't find the daemon " + address+ex.Message); } }