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 paxPosted Jul 21, 2009, 12:52 AM
It could be the passwordchar property of your textbox set to blank.
Pravara PatilPosted Jul 20, 2009, 1:20 AM
txtReceivedMsg.Text = "Hi";
still nothing is diaplayed.
I am not able to figure out the reason behind this kind of behaviour.
naura paxPosted Jul 19, 2009, 9:33 AM
Pravara PatilPosted Jul 17, 2009, 11:24 AM
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 paxPosted Jul 17, 2009, 9:56 AM
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 PatilPosted Jul 17, 2009, 6:34 AM
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 paxPosted Jul 17, 2009, 5:05 AM
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.