
Program Code – File Server Program
//------------------------------------------------------------
// Metropolia University of Applied Sciences
// Marcel Mushik 24 April 2011
// Final year project - Electronic class schedule
// Code: File server program
//------------------------------------------------------------
// Include files ----------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq; using
System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace Server_App
{
public partial class Form1 : Form
{
private Socket connection;
private NetworkStream socketStream;
private BinaryReader reader;
private BinaryWriter writer;
private Thread serverThread;
TcpListener server = null;
Appendix 2
12(15)
//
//
//
//
//
//
Function description---------------------------------------------
This function creates a server service that listens for incoming requests.
As a request is received, the respective file is located and the file size is sent.
The number of 512 byte sectors is also sent, for loop control in the Electronic class schedule program.
The program then waits for a start bit signifying that it can send the raw file data.
When the raw data is sent, the file server program ends the connection and begins to listen again.
public void RunServer()
{
try
{
// Fetches local IP address
string hostname = Dns.GetHostName();
IPAddress[] ips = Dns.GetHostAddresses(hostname);
string ip = String.Empty;
if (ips.Length > 0)
{
ip = ips[0].ToString();
}
// Creates listener port 2000 local IP address
Int32 port = 2000;
IPAddress localAddr = IPAddress.Parse(ip); server
= new TcpListener(localAddr, port);
Comentários a estes Manuais