HELP PLEASE - Modifying Open-Source Project
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: HELP PLEASE - Modifying Open-Source Project

  1. #1
    Join Date
    Jan 2010
    Posts
    6

    Talking HELP PLEASE - Modifying Open-Source Project

    first of all, hi new to the forums looking for some help (asked at other places too but they didnt seem to know)


    ok the problem i have is i have downloaded an open source C# project (called yoozy.net - http://yoozy.sourceforge.net/) which allows you to access the files on a server running yoozy

    i want to change it so that instead of the server application listening for the client, it does it the opposite way round so the 'server' app connects to the client this way i will be able to use it to access my files at home when im at school or at my dads.

    i have some c# knowledge however not in sockets and stuff and i have tried to learn and made a chat application but the two different apps from yoozy use different things to connect to each other (netstream.cs are different) so i cant just swap stream.connect("127.0.0.1",123) for stream.listen();

    if someone could have a look and help me (and tell me what they did) it will be appreciated
    thankyou

    here is the source for yoozy : http://downloads.sourceforge.net/pro..._mirror=heanet

  2. #2
    Join Date
    Jan 2010
    Posts
    6

    Re: HELP PLEASE - Modifying Open-Source Project

    anyone?

  3. #3
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: HELP PLEASE - Modifying Open-Source Project

    Quote Originally Posted by xSuper View Post
    anyone?
    people here are not robots scanning the forum every few minutes they're human beings and volunteers and answering questions is not obligatory so be patient and maybe someone will help you
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  4. #4
    Join Date
    Jan 2010
    Posts
    6

    Thumbs up Re: HELP PLEASE - Modifying Open-Source Project

    wow your not a bell end :sarcasm:

    any way thanks for bumping the post

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: HELP PLEASE - Modifying Open-Source Project

    You are unlikely to find someone who will read an entire project and explain it to you. If you don't know what you are doing there are resources all over the net that can help you. If you then have a *specific* question come back here and we may be able to help.

  6. #6
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: HELP PLEASE - Modifying Open-Source Project

    Agggh another "YOUR" person!

    Yes, people here will help, but specifics are needed.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  7. #7
    Join Date
    Jan 2010
    Posts
    6

    Re: HELP PLEASE - Modifying Open-Source Project

    hey biged and rliq

    @ biged hey i think you misunderstood me, im not looking for someone to read through the project and explain it to me, im quite competent in C# myself.

    however it seems i have hit a brick wall with this thing and there is a small section of code (mainly netcl.cs) which im asking an experienced c# programmer to look at and give me ideas or help me to achieve my goal. this shouldnt be too hard for a programmer who knows a fair bit about sockets and things. thanks anyways

    @rliq thanks for the reply and i thought i have been specific . is there anything else you need to know?

  8. #8
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: HELP PLEASE - Modifying Open-Source Project

    You may get more/quicker responses, if you copy the bit of code in question and paste it between [C0DE] [/C0DE] tags here....
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  9. #9
    Join Date
    Jan 2010
    Posts
    6

    Re: HELP PLEASE - Modifying Open-Source Project

    client netstream.cs

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;
    
    using Yoozy;
    
    namespace netcl
    {
        public  partial class NetStream
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
            Socket accepted = null;
    
            IPEndPoint local = null;
    
            int port = 28137;
    
            string delimiter = "netcl_end";
    
            public event _OnConnect OnConnect;
            public event _OnAccept OnAccept;
            public event _OnCloseConnection OnCloseConnection;
            public event _UpdateTraffic OnUpdate;
    
            private event _CommandQuery OnCommandQuery;
    
            byte[] buffer = new byte[1024000];
    
            Store store = new Store();
    
            bool busy = false;
            bool is_file_in_progress = false;
    
            Encoding unc = Encoding.Default;
    
            long in_traffic = 0;
            long out_traffic = 0;
           
            Compression compress = new Compression();
    
            bool _connected;
    
            public NetStream()
            {
                local = new IPEndPoint(IPAddress.Any, port);
                _connected = false;
            }
    
            public NetStream(int Port)
            {
                local = new IPEndPoint(IPAddress.Any, port);
            }
    
            ~NetStream()
            {
                socket.Close();
                if (accepted != null)
                {
                    _connected = false;
                    accepted.Close();
                }
            }
    
    
            public bool isBusy
            {
                get
                {
                    return busy;
                }
                set
                {
                    busy = value;
                }
            }
    
            public bool isFileOperation
            {
                get
                {
                    return is_file_in_progress;
                }
                set
                {
                    is_file_in_progress = value;
                }
            }
    
            /// <summary>
            /// Gets or sets data delemiter
            /// </summary>
            public string Delimiter
            {
                set
                {
                    delimiter = value;
                }
                get
                {
                    return delimiter;
                }
            }
    
            /// <summary>
            /// Async connect to host (OnConnect event)
            /// </summary>
            /// <param name="address">Ip address of host</param>
            /// <param name="port">Port number</param>
            public void Connect(string address, int port)
            {
                try
                {
                    accepted = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    IPAddress addr = IPAddress.Parse(address);
                    accepted.BeginConnect(addr, port, new AsyncCallback(ConnectCallback), null);
                }
                catch (Exception ex)
                {
                    _connected = false;
                    OnCloseConnection(ex.Message);
                }
            }
    
            public void Disconnect()
            {
                Shutdown("Disconnected by user");
            }
            
            /// <summary>
            /// Async listen
            /// </summary>
            public void Listen()
            {
                try
                {
                    socket.Bind(local);
                    socket.BeginAccept(new AsyncCallback(AcceptCallback), null);
                }
                catch (Exception ex)
                {
                    _connected = false;
                    Shutdown(ex.Message);
                    return;
                }
            }
    
            
            /// <summary>
            /// Async recieve data
            /// </summary>
            /// <param name="callback">Delegate to call when data to be recieved</param>
            public void RecieveData(_OnRecieveData callback)
            {
                try
                {
                    accepted.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(RecieveCallback), callback);
                }
                catch (Exception ex)
                {
                    _connected = false;
                    Shutdown(ex.Message);
                    return;
                }
            }
    
           
            /// <summary>
            /// Async send data
            /// </summary>
            /// <param name="data">data to send</param>
            /// <param name="callback">delegate to call, when data will be sended</param>
            public void SendData(byte[] data, _OnSendData callback)
            {
                try
                {
                    accepted.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), callback);
                }
                catch (Exception ex)
                {
                    _connected = false;
                    Shutdown(ex.Message);
                    return;
                }
    
            }
    
            void Shutdown(string msg)
            {
                _connected = false;
                OnCloseConnection(msg);
                if (accepted != null)
                {
                    accepted.Close();
                }
                socket.Close();
            }
    
            public bool Connected
            {
                get
                {
                    return _connected;
                }
            }
    
            /// <summary>
            /// Send command and recieve answer
            /// </summary>
            /// <param name="cmd">Command name</param>
            /// <param name="callback">Delegate to call, when answer recieved</param>
            public void CommandQuery(string cmd, _CommandQuery callback)
            {
                OnCommandQuery = callback;
                string c_cmd = compress.CompressData(cmd);
                SendData(Encoding.Default.GetBytes(c_cmd + delimiter), new _OnSendData(CQsendOK));
            }
    
            private void CQsendOK(int b)
            {
                RecieveData(new _OnRecieveData(CQRecieveOK));
            }
    
            private void CQRecieveOK(byte[] data)
            {
                byte[] decompressed = compress.DecompressData(data);
                OnCommandQuery(decompressed);            
            }
        }
    }

  10. #10
    Join Date
    Jan 2010
    Posts
    6

    Re: HELP PLEASE - Modifying Open-Source Project

    Server Netstream.cs

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Net.Sockets;
    
    namespace Network
    {
        public delegate void _OnConnect();
        public delegate void _OnAccept(string name);    
        public delegate void _OnRecieveData(byte[] data);
        public delegate void _OnSendData(int bytes);    
        public delegate void _OnCloseConnection();
    
        public class NetStream
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
            Socket accepted = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    
            IPEndPoint local = null;
    
            int port = 28137;
    
            public string delimiter = "netcl_end";
    
            public string file_delimiter = "netcl_end_file";
    
            byte[] signature;
    
            byte[] buffer = new byte[1024];
    
            public event _OnConnect         OnConnect;
            public event _OnAccept          OnAccept;
            public event _OnCloseConnection OnCloseConnection;
    
            StringBuilder builder = new StringBuilder();
    
            public NetStream()
            {
                signature = Encoding.Default.GetBytes(file_delimiter);
            }
    
            public NetStream(int port)
            {
                local = new IPEndPoint(IPAddress.Any, port);
                signature = Encoding.Default.GetBytes(file_delimiter);
            }
    
            ~NetStream()
            {
                if (socket.Connected)
                {
                    socket.Shutdown(SocketShutdown.Both);
                    socket.Close();
                }
                if (accepted.Connected)
                {
                    accepted.Shutdown(SocketShutdown.Both);
                    accepted.Close();
                }
            }
    
            /// <summary>
            /// Get or sets local port
            /// </summary>
            public int Port
            {
                set
                {
                    port = value;
                    local = new IPEndPoint(IPAddress.Any, port);
                }
                get
                {
                    return port;
                }
            }
            public void Connect(string address, int port)
            {
                accepted = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress addr = IPAddress.Parse(address);
                accepted.BeginConnect(addr, port, new AsyncCallback(ConnectCallback), null);
            }
    
            public void Shutdown()
            {
                if (socket.Connected)
                {
                    socket.Shutdown(SocketShutdown.Both);
                }
                if (accepted.Connected)
                {
                    accepted.Shutdown(SocketShutdown.Both);
                 }
                socket.Close();
                accepted.Close();
            }
    
            private void ConnectCallback(IAsyncResult ir)
            {
                try
                {
                    accepted.EndConnect(ir);
                    if (OnConnect != null)
                    {
                        OnConnect();
                    }
                }
                catch (Exception)
                {
                    OnCloseConnection();
                }
            }
    
            public void AsyncListen()
            {
                socket.Bind(local);
                socket.BeginAccept(new AsyncCallback(AcceptCallback), null);
            }
    
            public void Listen()
            {
                socket.Bind(local);
                socket.Listen(1);
                accepted = socket.Accept();
            }
    
            private void AcceptCallback(IAsyncResult ir)
            {
                accepted = socket.EndAccept(ir);
                if (accepted != null)
                {
                    if (OnAccept != null)
                    {
                        OnAccept(accepted.LocalEndPoint.ToString());
                    }
                }
            }
    
            public byte[] Recieve()
            {
                //YoozyServer.FileLogger.Write("Recieve::");
                StringBuilder str = new StringBuilder();
                int r = accepted.Receive(buffer, 1024, SocketFlags.None);
                string data = Encoding.Default.GetString(buffer, 0, r);
                str.Append(data);
                if (str.ToString().EndsWith(delimiter))
                {
                    string recv = str.ToString().Replace(delimiter, "");
                    //YoozyServer.FileLogger.Write("Recieve::recieved: " + recv);
                    byte[] byte_recv = Encoding.Default.GetBytes(recv);
                    //byte[] decompressed = compress.DecompressData(byte_recv);
                    return byte_recv;
                }
                else
                {
                    do
                    {
                        r = accepted.Receive(buffer, 1024, SocketFlags.None);
                        if (r == 0)
                        {
                            throw new SocketException();
                        }
                        data = Encoding.Default.GetString(buffer, 0, r);
                        str.Append(data);
                    }
                    while (!str.ToString().EndsWith(delimiter));
                    //prepare
                    string recv = str.ToString().Replace(delimiter, "");
                    byte[] byte_recv = Encoding.Default.GetBytes(recv);
                    //byte[] decompressed = compress.DecompressData(byte_recv);
                    return byte_recv;
                }
            }
    
            bool IsFileEndSignature(byte[] source, byte[] sign)
            {
                if (source.Length == sign.Length)
                {
                    for (int i = 0; i < sign.Length; i++)
                    {
                        if (source[i] != sign[i])
                        {
                            return false;
                        }
                    }
                }
                else
                {
                    return false;
                }
                return true;
            }
    
            public void Send(byte[] data)
            {
                accepted.Send(data);
            }
        }
    }

    this is how it is when its downloaded. the client has listen() in it for some reason but its asynchronous i swapped it for the servers listen method and the server connect method for the client connect and it does kinda work, although if i press "listen" on client it then hangs until i start the server and then carrys on working as normal but without a connection and the server crashs

    its easier to understand if you looked at the source

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center