­Portal­Home­Calendar­FAQ­Search­Memberlist­Usergroups­Register­Log in­
Post new topic   Reply to topicShare | 
 

 File Server

View previous topic View next topic Go down 
AuthorMessage
Vengeance
Coder
Coder


Posts: 11
Ultras: 11
Fame: 0
Join date: 2009-05-03

PostSubject: File Server   Mon May 04, 2009 2:31 am

Going to use this for Auto-Updating, just have to finish the client.

GUI:
Spoiler:
 

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace FileServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string hostName = "127.0.0.1";
            string path = textBox1.Text;
            int port = Convert.ToInt32(textBox2.Text.ToString());


            label1.Text = "Status: Running";
            MessageBox.Show("Server is now running!");
            IPAddress localAddr = IPAddress.Parse(hostName);



            TcpListener tcpL = new TcpListener(localAddr, port);
            tcpL.Start();

            for (; ; )
            {
                Socket socket = tcpL.AcceptSocket();
                if (socket.Connected)
                {
                    SendFileToClient(socket);
                    socket.Close();
                }
            }


        }

        void SendFileToClient(Socket socket)
        {
            string path = textBox1.Text;
            NetworkStream netStream = new NetworkStream(socket);
            StreamWriter writer = new StreamWriter(netStream);



            FileStream fileStream = File.Open(path + "/Gunz.exe", FileMode.Open, FileAccess.Read, FileShare.Read);
            FileStream fileStream2 = File.Open(path + "/GunzLauncher.exe", FileMode.Open, FileAccess.Read, FileShare.Read);
            FileStream fileStream3 = File.Open(path + "/system.mrs", FileMode.Open, FileAccess.Read, FileShare.Read);

            StreamReader reader = new StreamReader(fileStream);
            StreamReader reader2 = new StreamReader(fileStream2);
            StreamReader reader3 = new StreamReader(fileStream3);

            string strReadLine = null;
            string strReadLine2 = null;
            string strReadLine3 = null;
            do
            {
                strReadLine = reader.ReadLine();
                strReadLine2 = reader2.ReadLine();
                strReadLine3 = reader3.ReadLine();

                if (strReadLine != null && strReadLine2 != null && strReadLine3 != null)
                {
                    writer.WriteLine(strReadLine);
                    writer.WriteLine(strReadLine2);
                    writer.WriteLine(strReadLine3);
                }

                writer.Flush();

            }
            while (strReadLine != null && strReadLine2 != null && strReadLine3 != null);
            writer.Close();
        }
           

        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Remember to not include the last forward-slash in the path!");
        }
    }
}
Back to top Go down
View user profile
Solar
Head Developer
Head Developer


Posts: 66
Ultras: 77
Fame: 2
Join date: 2009-04-29

PostSubject: Re: File Server   Mon May 04, 2009 3:31 am

Nice work.
Back to top Go down
View user profile
Tributized
Developer
Developer


Posts: 9
Ultras: 16
Fame: 1
Join date: 2009-04-28

PostSubject: Re: File Server   Mon May 04, 2009 5:15 am

good job 0.0
Back to top Go down
View user profile
 

File Server

View previous topic View next topic Back to top 
Page 1 of 1

Permissions of this forum:You cannot reply to topics in this forum
 :: Ultra GunZ Server // :: Development Zone //-
Post new topic   Reply to topic