Network

Public Methods

  • Network(IPAddress, int) - Constructor for starting a connection.
  • Network(string, int) - Constructor for starting a connection.
  • Network(int) - Constructor for waiting for a connection.
  • Network(TcpClient) - Constructor for an established connection.
  • SendFile(string) - Send a file to the connected host.
  • BeginSendFile(string) - Asynchronously send a file to the connected host.
  • GetFile(string) - Get a file from the connected host.
  • BeginGetFile(string) - Asynchronously get a file from the connected host.
  • SendObject(object) - Send an object to the connected host.
  • BeginSendObject(object) - Asynchronously send an object to the connected host.
  • object GetObject() - Get an object from the connected host.
  • object BeginGetObject() - Asynchronously get an object from the connected host.
  • Close() - Disconnect from client.

Public Properties

  • DateTime LastComm - Access for the time of last communication sent or received.
  • bool Active - A check to see if the connection is still active.

Private Methods

  • initialization() - Initialization stuff.
  • startConnection() - Function for thread to establish a connection on.
  • listenForConnection() - Function for thread to listen for a connection on.
  • Network_Connected(object, EventArgs) - Handles the connection established event.
  • listenForData() - Listens for data to come down the pipe.
  • getFile(object) - Get a file from a connected host.
  • sendObject(object) - Sends an object to the connected host.
  • getObject(object) - Function that gets an object.
  • sendFile(object) - Send a file to the connected host.

Private Properties

  • bool DataAvailable - Locked access for the data waiting object.
  • bool StopListen - Locked access for the thread stop object.

Private Data Members

  • Thread listenThread - Thread that will listen for various things.
  • int port - Port that will be used in connection
  • IPAddress ip - IP address to connect to.
  • TcpClient tcpClient - TcpClient that will be used make a connection.
  • TcpListener tcpListener - TcpListener that will be used to wait for a connection.
  • DateTime lastComm - The time of the last communication.
  • bool dataIsWaiting - A bool to tell whether or not there is data waiting.
  • object dataLock - An object to lock on for changing dataIsWaiting.
  • object sendLock - An object to lock on for thread concurrency during send.
  • object getLock - An object to lock on for thread concurrency during get.
  • bool stopListen - Tells threads to stop.
  • object stopListenLock - An object to lock on for changing stopListen.

Events

  • Connected - Notifies that a connection has been established.
  • Disconnected - Notifies that a connection has been terminated.
  • ObjectWaiting - Notifies that there is an object on the stream.
  • ObjectComplete - Notifies that an object transfer is complete.
  • FileWaiting - Notifies that there is a file on the stream.
  • FileComplete - Notifies that a file transfer is complete.

Remarks

  • When responding to the events in a form, BeginUpdate may be necessary since the event notifications are made on seperate threads.
  • When responding to an event fired by network, use the following in the function (change "FunctionName" to the name of the function):
   if (this.InvokeRequired)
   {
      // Pass the same function to BeginInvoke,
      // but the call would come on the correct
      // thread and InvokeRequired will be false.
      this.BeginInvoke(new EventHandler(FunctionName), 
         new object[] {sender, e});
      return;
   }

Topic revision: r4 - 12 Jul 2005, WillGray
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback