473,383 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

RE: write response to textbox from a class.

I'm sorry, but I've read your code a couple of times and just don't see where
the Form1 is initialized. Form1 also sounds like a class name, and this
would be how you could do some form operations in vb6, but not in .Net. This
would explain why the messagebox works, as it is not instantiated, but called
statically as you did in your code.

I think you need this where your MsgBox is called:

dim ui as New Form1()
ui.txt_rec.Text = "some message for you..."
ui.Show()
"hb21l6" wrote:
>
I have created a very very simple messanger application that i'm having a
problem with.
I can send data back and forth between PC's using the TCPlistener and
TCPclient
in system.net.sockets, which I think is very cool.

But I can't get it write the response into a textbox??

see below
if I use the standard format of assigning text to a textbox object like
this, it doesnt work.

Form1.txt_rec.Text = "their response: " + data.ToString + vbCrLf
But, if I write out the same value to a msgbox, it works fine?
MsgBox(data)
what does happen thou, is that it sets focus on the text box, just doesnt
write the response to the box.
Anyone got any ideas?
Below is the class that tries to insert the response into the textbox.

Class TCPSrv
Shared Sub Main()

Dim server As TcpListener
server = Nothing
' Set the TcpListener on port 13000.
Dim port As Int32 = 13000
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

server = New TcpListener(IPAddress.Any, port)

' Start listening for client requests.

server.Start()

' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
While True
Console.Write("Waiting for a connection... ")

' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = server.AcceptTcpClient()

' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()

Dim i As Int32

' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

Form1.txt_rec.Text = data
MsgBox(data)
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Encoding.ASCII.GetBytes(data)

' Send back a response.
stream.Write(msg, 0, msg.Length)
i = stream.Read(bytes, 0, bytes.Length)

End While
' Shutdown and end connection
' client.Close()
End While
' once we're finished recieving - start it listening again.
' Main()
End Sub
End Class
Sep 26 '08 #1
5 2341

Thanks for the reply Mike
Form1 is already open and it calls the TCPSvr.main() function within the
class shown below.

[formname].[Textbox object].[property]
Form1.txt_rec.Text is inside the class. so when its called, it can update
the textbox, but it isn't

thats the bit that I dont understand.

Form1.txt_rec.text is in the class below?

cheers
Dave


"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:4D**********************************@microsof t.com...
I'm sorry, but I've read your code a couple of times and just don't see
where
the Form1 is initialized. Form1 also sounds like a class name, and this
would be how you could do some form operations in vb6, but not in .Net.
This
would explain why the messagebox works, as it is not instantiated, but
called
statically as you did in your code.

I think you need this where your MsgBox is called:

dim ui as New Form1()
ui.txt_rec.Text = "some message for you..."
ui.Show()
"hb21l6" wrote:
>>
I have created a very very simple messanger application that i'm having a
problem with.
I can send data back and forth between PC's using the TCPlistener and
TCPclient
in system.net.sockets, which I think is very cool.

But I can't get it write the response into a textbox??

see below
if I use the standard format of assigning text to a textbox object like
this, it doesnt work.

Form1.txt_rec.Text = "their response: " + data.ToString +
vbCrLf
But, if I write out the same value to a msgbox, it works fine?
MsgBox(data)
what does happen thou, is that it sets focus on the text box, just doesnt
write the response to the box.
Anyone got any ideas?
Below is the class that tries to insert the response into the textbox.

Class TCPSrv
Shared Sub Main()

Dim server As TcpListener
server = Nothing
' Set the TcpListener on port 13000.
Dim port As Int32 = 13000
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

server = New TcpListener(IPAddress.Any, port)

' Start listening for client requests.

server.Start()

' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
While True
Console.Write("Waiting for a connection... ")

' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = server.AcceptTcpClient()

' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()

Dim i As Int32

' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

Form1.txt_rec.Text = data
MsgBox(data)
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Encoding.ASCII.GetBytes(data)

' Send back a response.
stream.Write(msg, 0, msg.Length)
i = stream.Read(bytes, 0, bytes.Length)

End While
' Shutdown and end connection
' client.Close()
End While
' once we're finished recieving - start it listening again.
' Main()
End Sub
End Class
Sep 26 '08 #2
Are you running TCPSvr.main() in a BackgroundWorker? It sounds like you
should be if you are not. You then will probably need to call invoke on the
textbox to update it.

"hb21l6" wrote:
>
Thanks for the reply Mike
Form1 is already open and it calls the TCPSvr.main() function within the
class shown below.

[formname].[Textbox object].[property]
Form1.txt_rec.Text is inside the class. so when its called, it can update
the textbox, but it isn't

thats the bit that I dont understand.

Form1.txt_rec.text is in the class below?

cheers
Dave


"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:4D**********************************@microsof t.com...
I'm sorry, but I've read your code a couple of times and just don't see
where
the Form1 is initialized. Form1 also sounds like a class name, and this
would be how you could do some form operations in vb6, but not in .Net.
This
would explain why the messagebox works, as it is not instantiated, but
called
statically as you did in your code.

I think you need this where your MsgBox is called:

dim ui as New Form1()
ui.txt_rec.Text = "some message for you..."
ui.Show()
"hb21l6" wrote:
>
I have created a very very simple messanger application that i'm having a
problem with.
I can send data back and forth between PC's using the TCPlistener and
TCPclient
in system.net.sockets, which I think is very cool.

But I can't get it write the response into a textbox??

see below
if I use the standard format of assigning text to a textbox object like
this, it doesnt work.

Form1.txt_rec.Text = "their response: " + data.ToString +
vbCrLf
But, if I write out the same value to a msgbox, it works fine?
MsgBox(data)
what does happen thou, is that it sets focus on the text box, just doesnt
write the response to the box.
Anyone got any ideas?
Below is the class that tries to insert the response into the textbox.

Class TCPSrv
Shared Sub Main()

Dim server As TcpListener
server = Nothing
' Set the TcpListener on port 13000.
Dim port As Int32 = 13000
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

server = New TcpListener(IPAddress.Any, port)

' Start listening for client requests.

server.Start()

' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
While True
Console.Write("Waiting for a connection... ")

' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = server.AcceptTcpClient()

' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()

Dim i As Int32

' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

Form1.txt_rec.Text = data
MsgBox(data)
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Encoding.ASCII.GetBytes(data)

' Send back a response.
stream.Write(msg, 0, msg.Length)
i = stream.Read(bytes, 0, bytes.Length)

End While
' Shutdown and end connection
' client.Close()
End While
' once we're finished recieving - start it listening again.
' Main()
End Sub
End Class
Sep 26 '08 #3

Yeah, its running as a seperate thread uwing backgroundWorker.

Do i invoke the object on the buttonClick event or in the class after its
assigned the data to it?

cheers
Dave
"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:B2**********************************@microsof t.com...
Are you running TCPSvr.main() in a BackgroundWorker? It sounds like you
should be if you are not. You then will probably need to call invoke on
the
textbox to update it.

"hb21l6" wrote:
>>
Thanks for the reply Mike
Form1 is already open and it calls the TCPSvr.main() function within the
class shown below.

[formname].[Textbox object].[property]
Form1.txt_rec.Text is inside the class. so when its called, it can
update
the textbox, but it isn't

thats the bit that I dont understand.

Form1.txt_rec.text is in the class below?

cheers
Dave


"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:4D**********************************@microsof t.com...
I'm sorry, but I've read your code a couple of times and just don't see
where
the Form1 is initialized. Form1 also sounds like a class name, and
this
would be how you could do some form operations in vb6, but not in .Net.
This
would explain why the messagebox works, as it is not instantiated, but
called
statically as you did in your code.

I think you need this where your MsgBox is called:

dim ui as New Form1()
ui.txt_rec.Text = "some message for you..."
ui.Show()
"hb21l6" wrote:
I have created a very very simple messanger application that i'm
having a
problem with.
I can send data back and forth between PC's using the TCPlistener and
TCPclient
in system.net.sockets, which I think is very cool.

But I can't get it write the response into a textbox??

see below
if I use the standard format of assigning text to a textbox object
like
this, it doesnt work.

Form1.txt_rec.Text = "their response: " + data.ToString +
vbCrLf
But, if I write out the same value to a msgbox, it works fine?
MsgBox(data)
what does happen thou, is that it sets focus on the text box, just
doesnt
write the response to the box.
Anyone got any ideas?
Below is the class that tries to insert the response into the textbox.

Class TCPSrv
Shared Sub Main()

Dim server As TcpListener
server = Nothing
' Set the TcpListener on port 13000.
Dim port As Int32 = 13000
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

server = New TcpListener(IPAddress.Any, port)

' Start listening for client requests.

server.Start()

' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
While True
Console.Write("Waiting for a connection... ")

' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = server.AcceptTcpClient()

' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()

Dim i As Int32

' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

Form1.txt_rec.Text = data
MsgBox(data)
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Encoding.ASCII.GetBytes(data)

' Send back a response.
stream.Write(msg, 0, msg.Length)
i = stream.Read(bytes, 0, bytes.Length)

End While
' Shutdown and end connection
' client.Close()
End While
' once we're finished recieving - start it listening again.
' Main()
End Sub
End Class
Sep 27 '08 #4
it would appear that this is a common thing,

http://blogs.msdn.com/tobint/archive...Threading.aspx
I'll try to implement this, 'just like you said mike' and see if it solves
the issue.

Dave
"hb21l6" <hb****@hotmail.comwrote in message
news:86**********************************@microsof t.com...
>
Yeah, its running as a seperate thread uwing backgroundWorker.

Do i invoke the object on the buttonClick event or in the class after its
assigned the data to it?

cheers
Dave
"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:B2**********************************@microsof t.com...
>Are you running TCPSvr.main() in a BackgroundWorker? It sounds like you
should be if you are not. You then will probably need to call invoke on
the
textbox to update it.

"hb21l6" wrote:
>>>
Thanks for the reply Mike
Form1 is already open and it calls the TCPSvr.main() function within the
class shown below.

[formname].[Textbox object].[property]
Form1.txt_rec.Text is inside the class. so when its called, it can
update
the textbox, but it isn't

thats the bit that I dont understand.

Form1.txt_rec.text is in the class below?

cheers
Dave


"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:4D**********************************@microsof t.com...
I'm sorry, but I've read your code a couple of times and just don't
see
where
the Form1 is initialized. Form1 also sounds like a class name, and
this
would be how you could do some form operations in vb6, but not in
.Net.
This
would explain why the messagebox works, as it is not instantiated, but
called
statically as you did in your code.

I think you need this where your MsgBox is called:

dim ui as New Form1()
ui.txt_rec.Text = "some message for you..."
ui.Show()
"hb21l6" wrote:
I have created a very very simple messanger application that i'm
having a
problem with.
I can send data back and forth between PC's using the TCPlistener and
TCPclient
in system.net.sockets, which I think is very cool.

But I can't get it write the response into a textbox??

see below
if I use the standard format of assigning text to a textbox object
like
this, it doesnt work.

Form1.txt_rec.Text = "their response: " + data.ToString +
vbCrLf
But, if I write out the same value to a msgbox, it works fine?
MsgBox(data)
what does happen thou, is that it sets focus on the text box, just
doesnt
write the response to the box.
Anyone got any ideas?
Below is the class that tries to insert the response into the
textbox.

Class TCPSrv
Shared Sub Main()

Dim server As TcpListener
server = Nothing
' Set the TcpListener on port 13000.
Dim port As Int32 = 13000
Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")

server = New TcpListener(IPAddress.Any, port)

' Start listening for client requests.

server.Start()

' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
While True
Console.Write("Waiting for a connection... ")

' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = server.AcceptTcpClient()

' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()

Dim i As Int32

' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

Form1.txt_rec.Text = data
MsgBox(data)
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Encoding.ASCII.GetBytes(data)

' Send back a response.
stream.Write(msg, 0, msg.Length)
i = stream.Read(bytes, 0, bytes.Length)

End While
' Shutdown and end connection
' client.Close()
End While
' once we're finished recieving - start it listening again.
' Main()
End Sub
End Class


Sep 27 '08 #5
That was an interesting blog. Hopefully it gets you going.

"hb21l6" <hb****@hotmail.comwrote in message
news:A9**********************************@microsof t.com...
it would appear that this is a common thing,

http://blogs.msdn.com/tobint/archive...Threading.aspx
I'll try to implement this, 'just like you said mike' and see if it solves
the issue.

Dave
"hb21l6" <hb****@hotmail.comwrote in message
news:86**********************************@microsof t.com...
>>
Yeah, its running as a seperate thread uwing backgroundWorker.

Do i invoke the object on the buttonClick event or in the class after its
assigned the data to it?

cheers
Dave
"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:B2**********************************@microsof t.com...
>>Are you running TCPSvr.main() in a BackgroundWorker? It sounds like you
should be if you are not. You then will probably need to call invoke on
the
textbox to update it.

"hb21l6" wrote:


Thanks for the reply Mike
Form1 is already open and it calls the TCPSvr.main() function within
the
class shown below.

[formname].[Textbox object].[property]
Form1.txt_rec.Text is inside the class. so when its called, it can
update
the textbox, but it isn't

thats the bit that I dont understand.

Form1.txt_rec.text is in the class below?

cheers
Dave


"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:4D**********************************@microsof t.com...
I'm sorry, but I've read your code a couple of times and just don't
see
where
the Form1 is initialized. Form1 also sounds like a class name, and
this
would be how you could do some form operations in vb6, but not in
.Net.
This
would explain why the messagebox works, as it is not instantiated,
but
called
statically as you did in your code.

I think you need this where your MsgBox is called:

dim ui as New Form1()
ui.txt_rec.Text = "some message for you..."
ui.Show()
"hb21l6" wrote:
I have created a very very simple messanger application that i'm
having a
problem with.
I can send data back and forth between PC's using the TCPlistener
and
TCPclient
in system.net.sockets, which I think is very cool.

But I can't get it write the response into a textbox??

see below
if I use the standard format of assigning text to a textbox object
like
this, it doesnt work.

Form1.txt_rec.Text = "their response: " + data.ToString +
vbCrLf
But, if I write out the same value to a msgbox, it works fine?
MsgBox(data)
what does happen thou, is that it sets focus on the text box, just
doesnt
write the response to the box.
Anyone got any ideas?
Below is the class that tries to insert the response into the
textbox.

Class TCPSrv
Shared Sub Main()

Dim server As TcpListener
server = Nothing
' Set the TcpListener on port 13000.
Dim port As Int32 = 13000
Dim localAddr As IPAddress =
IPAddress.Parse("127.0.0.1")

server = New TcpListener(IPAddress.Any, port)

' Start listening for client requests.

server.Start()

' Buffer for reading data
Dim bytes(1024) As Byte
Dim data As String = Nothing
' Enter the listening loop.
While True
Console.Write("Waiting for a connection... ")

' Perform a blocking call to accept requests.
' You could also user server.AcceptSocket() here.
Dim client As TcpClient = server.AcceptTcpClient()

' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStream()

Dim i As Int32

' Loop to receive all the data sent by the client.
i = stream.Read(bytes, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)

Form1.txt_rec.Text = data
MsgBox(data)
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Encoding.ASCII.GetBytes(data)

' Send back a response.
stream.Write(msg, 0, msg.Length)
i = stream.Read(bytes, 0, bytes.Length)

End While
' Shutdown and end connection
' client.Close()
End While
' once we're finished recieving - start it listening again.
' Main()
End Sub
End Class

Sep 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PorkyJr | last post by:
Running an asp page that has the following code: <% response.Write MonthName(Month(date)) %> &nbsp; <% response.Write Day(date) %> ,
2
by: Jon Maz | last post by:
Hi, I have written a page to test a function of mine that strips non-English accents and various other characters out of a given string. The function itself (called 'StripAll' in the code below)...
14
by: Gidi | last post by:
Hi, For the last week, i'm looking for a way to make a TextBox always write in English (No matter what the OS default language is). i asked here few times but the answers i got didn't help me. i...
1
by: Rich | last post by:
Hello, in my ASP.NET c# project I can ouput text using response.write from the code behind class. It works in the aspx file using <asp:TextBox> controls too. It also works using <%="Hello"%>....
5
by: Michael | last post by:
Hello, I have a separate Database class that handles any database work that all my asp.net pages can use. My problem is, many times I use try/catch to catch errors, and I want to output these...
3
by: michael_vanommeren | last post by:
I have two web applications that I am working with and I am trying to do a Response.Redirect from one to the other. They are setup as separate web applications on the same IIS server. If I go...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.