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:
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.sock ets, 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.T ext = "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(IPA ddress.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.AcceptSo cket() here.
Dim client As TcpClient = server.AcceptTc pClient()
>
' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStrea m()
>
Dim i As Int32
>
' Loop to receive all the data sent by the client.
i = stream.Read(byt es, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Enc oding.ASCII.Get String(bytes, 0, i)
>
Form1.txt_rec.T ext = data
MsgBox(data)
>
>
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Enc oding.ASCII.Get Bytes(data)
>
' Send back a response.
stream.Write(ms g, 0, msg.Length)
>
>
i = stream.Read(byt es, 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
>
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.sock ets, 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.T ext = "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(IPA ddress.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.AcceptSo cket() here.
Dim client As TcpClient = server.AcceptTc pClient()
>
' clear data value data = Nothing
' Get a stream object for reading and writing
Dim stream As NetworkStream = client.GetStrea m()
>
Dim i As Int32
>
' Loop to receive all the data sent by the client.
i = stream.Read(byt es, 0, bytes.Length)
While (i <0)
' Translate data bytes to a ASCII string.
data = System.Text.Enc oding.ASCII.Get String(bytes, 0, i)
>
Form1.txt_rec.T ext = data
MsgBox(data)
>
>
' Process the data sent by the client.
data = data.ToUpper()
Dim msg As Byte() =
System.Text.Enc oding.ASCII.Get Bytes(data)
>
' Send back a response.
stream.Write(ms g, 0, msg.Length)
>
>
i = stream.Read(byt es, 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
>
Comment