Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 23rd, 2008, 10:27 PM
Authorized User
 
Join Date: Aug 2008
Location: manila, , Philippines.
Posts: 38
Thanks: 1
Thanked 0 Times in 0 Posts
Default problem retrieving data processed by class library

Pls help! how am i going to update a form's listbox with data handled and stored by a class library ( the messages are from a connected socket)?
I want this listbox to diplay chat messages.


class X (class library code)

properties: ipadd,port,isconnected...etc
methods:
    Connect() and ConnectCallback //will establish connection to the socket using BeginConnect and EndConnect
    WaitForData and OnDataReceived(Callback) //will received the messages using BeginReceive and EndReceive


        public void WaitForData()
        {
            recieveCallback = new AsyncCallback(onDataReceived);
            StateObject socket = new StateObject();
            socket.workSocket = mainClientSocket;
            result = mainClientSocket.BeginReceive(socket.buffer, 0, socket.buffer.Length, SocketFlags.None, recieveCallback, socket);
        }

        private void onDataReceived(IAsyncResult result)
        {
            StateObject socket = (StateObject)result.AsyncState;
            if (mainClientSocket.Connected)
            {

                bytesRcvd = socket.workSocket.EndReceive(result);
                ReadXML(bytesReceived, socket); //method that will parse the message
                receiveDone.Set();
                WaitForData();
            }
            else
            {
                socket.workSocket.Close();
            }
        }



        private void ReadXML(int bytes, StateObject socket)
        {
          ...
          ...
          ...
          Once data is parsed , it will be stored in SenderMessageList ///(List<string>)
            SenderMessageQueue(Sender + ": " + Message);
        }
        private void SenderMessageQueue(String message, String socketID)
        {
            SenderMessageList.Add(message);
        }

        public String getSenderMessage //// I will call this property in a form to display //// the stored message
        {
            get
            {
                return SenderMessageList[SenderMessageList.Count - 1];
            }
        }

Form // will use the library


namespace WindowsFormsApplication4
{
            using X;
           ..
           ..
            x= new X.ClientSocket();
            IntPtr handle = this.Handle;
            x.IPadd = "127.0.0.1";
            x.Port = 8222;
            x.Connect();

            ThreadStart threadStarter = new ThreadStart(ReceiveMessages);
            myThread = new Thread(threadStarter);
            myThread.IsBackground = true;
            myThread.Start();
        }

        private void ReceiveMessages()
        {

            while (x.bytesReceived != 0)
            {
                 listBox1.Invoke(new UpdateTextCallback(this.Update_listBox1), new object[] { a });

            }
            listBox1.Invoke(new UpdateTextCallback(this.Update_listBox1), new object[] { x.getSenderMessage });
         }

        private void Update_listBox1(String text)
        {
            listBox1.Items.Add(text);

        }
        private void ButtonSend_click{
            }

When i move the listbox.invoke in ButtonSend, i can get the stored message..But what i want to do is automate the receiving of data..Sending has no problem cause it's working...I am by the way creating a chat program..i want to see all the messages coming in...Thanks.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
use of class library Theone84 C# 1 July 26th, 2008 02:19 AM
Problem with returning value from class library labby C# 1 September 11th, 2006 08:50 AM
problem Extracting Data using HTML Object Library method VB How-To 0 May 12th, 2006 02:52 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM



All times are GMT -4. The time now is 07:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.