Hi There,
i am working on a windows application, which implements communication between two systems, using TCP/IP protocol.
my form contains a multiline text box, in which i want to display the text/data received.
i am reading data on the socket using asynchronous/non-blocking method. the method for reading data on socket is in different class.
My problem is: i get data on the socket, which i pass to a function on form. but the data is not displayed in the text box. the string if displayed in message box, it is dispalyed. in short, the function on main form gets data received by server, but it is not displayed in tex box.
Please help me in the matter.
Thanks in advance.
Loading

naura paxRank #2,843 · 502 reputationPosted Jul 17, 2009, 1:05 AM EDT
You've got to post your code to make it clear. Your class, the method you 've pointed out and also the form where you're trying to set textbox text property.
Pravara Patil37 reputationPosted Jul 17, 2009, 2:34 AM EDT
Form1.cs (which contains text box txtReceivedMsg ):
public void trial(string strMsg)
{
MessageBox.Show(strMsg);
txtReceivedMsg.AppendText(strMsg);
txtReceivedMsg.AppendText(System.Environment.NewLine);
}
the above function is called from a callback function in clsClass.cs class. here is the code:
public static void ReceiveData(IAsyncResult Ar)
{
clsTCPIP objTCPIP = (clsTCPIP)Ar.AsyncState;
NetworkStream networkStr = objTCPIP.netStream;
frmAdvTCPIP frm = new frmAdvTCPIP();
int intCount = 0;
while (objTCPIP.byData[intCount] != '\0' && intCount < objTCPIP.byData.Length)
{
++intCount;
string strReceived = Encoding.UTF8.GetString(objTCPIP.byData, 0, intCount).Trim();
if (strReceived.Length > 0)
{
objTCPIP.strMsgReceivedbyserver = strReceived;
}
}
try
{
int intBytesCount = networkStr.EndRead(Ar);
if (intBytesCount > 0)
{
// clean old data out of the buffer
for (int i = 0; i < intBytesCount; i++)
{
objTCPIP.byData[i] = 0;
}
networkStr.BeginRead(objTCPIP.byData, 0, objTCPIP.byData.Length, ReceiveData, objTCPIP);
}
frm.trial(objTCPIP.strMsgReceivedbyserver);
}
catch (IOException IOEx)
{
objTCPIP.ServerSock.Shutdown(SocketShutdown.Both);
objTCPIP.ServerSock.Close();
networkStr = null;
}
catch (Exception strEx)
{
objTCPIP.ServerSock.Shutdown(SocketShutdown.Both);
objTCPIP.ServerSock.Close();
networkStr = null;
}
finally
{
networkStr = null;
}
}
naura paxRank #2,843 · 502 reputationPosted Jul 17, 2009, 5:56 AM EDT
Have you set multiline property of your textbox (txtReceivedMsg) to true? If yes then either set it to false or increase the textbox's height.
Or simply remove line using txtReceivedMsg.AppendText(System.Environment.NewLine) from your code.
For test right now don't change code,just run your application and press delete button in your textbox several times.. you might see your text.
Please tell me if i'm correct.
Pravara Patil37 reputationPosted Jul 17, 2009, 7:24 AM EDT
still, i'll try by enabling scroll bars of the text box.
do you think the code has some instance issue?
i mean, new instance of form is being created, and due to that text box is not displaying the data?
naura paxRank #2,843 · 502 reputationPosted Jul 19, 2009, 5:33 AM EDT
Pravara Patil37 reputationPosted Jul 19, 2009, 9:20 PM EDT
txtReceivedMsg.Text = "Hi";
still nothing is diaplayed.
I am not able to figure out the reason behind this kind of behaviour.
naura paxRank #2,843 · 502 reputationPosted Jul 20, 2009, 8:52 PM EDT
It could be the passwordchar property of your textbox set to blank.