Results 1 to 8 of 8

Thread: stream reader writer

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    stream reader writer

    What i want to do is send a request to a listening server which i created and receive it, and then the server will reply with an answer. I am trying to get some mysql database values from an external listener program and receive them back to the program that requested them. Thats as best i can describe it. or maybe someone will tell me i am doing it a very dumb way and streamreader/writer is not the best way to do this, or is it??? I created an external app which holds the database info and connections to mysql server. It works perfect, but i dont know how i should go about requesting info from this program from another app i am using. Any suggestions on how you get database values from external listeners or mysql servers, would help me. So far my google searches come up with vague answers.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Re: stream reader writer

    I've got a client app which contains the UI and sends request for data to a WCF app that actually retrieves the data and sends it back. The whole purpose of Window's Communication Foundation (WCF) is to make inter-process communication easier, so if I were you I'd look into WCF.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: stream reader writer

    Thanks for the reply hongkong but that doesn't exactly help me since i am using vb to make a project which i spent a lot of time building. any suggestions on how this can be done would be great!




    i am trying to do it just as hongkongs app does it. :/

  4. #4
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Re: stream reader writer

    First, there are tons of books and online tutorials about writing WCF apps... I can't cover all of that in one forum post.

    That said, you've got the general idea... you have a client app and a server app. With WCF, the server app defines the interface data objects and function calls that it supports, and the client app uses those interface objects to both request/send data to the server and store the data sent from the server.

    The server implements data and functions as follows (the only one I've written so far is in C#... sorry):

    Code:
        [ServiceContract]
        public interface IPolicyMaintenanceService
        {
            [OperationContract]
            [FaultContract(typeof(PolicyFault))]
            String GetDBInformation();
    
            [OperationContract]
            [FaultContract(typeof(PolicyFault))]
            List<Policy> GetPolicyByName(String policyName);
        }
    
        [DataContract]
        public class Policy
        {
            [DataMember]
            public int PolicyID { get; set; }
            [DataMember]
            public String PolicyNum { get; set; }
            [DataMember]
            public List<PolicyGroup> Groups { get; set; }
        }
    
        [DataContract]
        public class PolicyGroup
        {
            [DataMember]
            public int GroupID { get; set; }
            [DataMember]
            public int PolicyID { get; set; }
            [DataMember]
            public int? GroupNum { get; set; }
        }
    So I have two datatypes, PolicyGroup and Policy... Policy contains a list of groups. There are two functions that can called to request data from the server. The first, GetDBInformation(), returns a string containing the server and database name to which the server is connected and getting its data from. The second allows the user to send in a policy name and get back a list of policies that have that name. I programmed it similar to a like, so that the server returns all policies that BEGIN with the name sent to the server. You can make changes to the returned data and then define interface functions to pass the changed data back to the server, which will have to handle the modifications.

    Here's one link (of many available) to a tutorial-style write-up on how to create this kind of application:
    http://www.codeproject.com/Articles/...anding-Windows

    If you're interested in books, my first book was "WCF 4.5 Multi-Layer Services Development with Entity Framework (Third Edition)" by Mike Liu. It walks you through the whole process of developing exactly the kind of application we're discussing... it's a tutorial-style book, and not really a book good for reference.I also recommend "Programming WCF Services" by Juval Lowy... an excellent reference text.

    Also try this link.. it links to several tutorials on the subject:
    http://msdn.microsoft.com/en-us/library/ms734712.aspx
    Last edited by HongKongCV; Aug 8th, 2013 at 11:27 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: stream reader writer

    I am doing this in VB dude not WPF and i cant change my language just because WPF is easier for this kind of communication stuff
    i started my project in vb and wont change that now but thanks for your help.
    What i need to know is how to do what you described in VB.

    Anyone got any pointers or code examples in VB for me to follow????

  6. #6
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: stream reader writer

    Quote Originally Posted by Mucker View Post
    I am doing this in VB dude not WPF and i cant change my language just because WPF is easier for this kind of communication stuff
    i started my project in vb and wont change that now but thanks for your help.
    What i need to know is how to do what you described in VB.

    Anyone got any pointers or code examples in VB for me to follow????
    HongKongCV is suggesting you make a Windows Communication Foundation (WCF) service. You're mixing it up with a Windows Presentation Foundation (WPF) application.

    Here's a good starting point for WCF services: Link

    If you still want to go the listener way jmcilhinney wrote an excellent post about tcplisteners and tcpclients: Link
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  7. #7
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Re: stream reader writer

    Thanks, MattP. Yes, there is a massive difference between Windows Presentation Foundation (WPF) and Windows Communication Foundation (WCF). The second is merely a method for writing client-server apps, and you can easily do so in VB. Everything I described could be done with VB applications... visit some of the links that I and MattP provided for a rundown on WCF. Many give coding examples in both C# and VB...

    Personally, I've found the WCF approach to be more reliable than a tcp listener approach. Possibly that's just me, but it IS my experience.

    Best of luck, Mucker.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2013
    Posts
    312

    Re: stream reader writer

    Quote Originally Posted by MattP View Post
    HongKongCV is suggesting you make a Windows Communication Foundation (WCF) service. You're mixing it up with a Windows Presentation Foundation (WPF) application.

    Here's a good starting point for WCF services: Link

    If you still want to go the listener way jmcilhinney wrote an excellent post about tcplisteners and tcpclients: Link
    From what I read, the problem with TCP read / writers is they require a port for each user connected? Opposite for UDP.. if thats right, then i will also need to go the UDP road. Thanks for the WCF link Matt. And sorry to hongkong for the misunderstanding on my part. I misread wcf as wpf

    if i go wcf road, then i would need to create a multi project or not?

Posting Permissions

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



Click Here to Expand Forum to Full Width