RE: write response to textbox from a class.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

    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.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
    >
  • hb21l6

    #2
    Re: write response to textbox from a class.




    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.T ext 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.t ext is in the class below?

    cheers
    Dave






    "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
    message news:4DADB054-66A2-4CAB-B49B-3A9A3E968DF6@mi crosoft.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.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.En coding.ASCII.Ge tBytes(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

    • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

      #3
      Re: write response to textbox from a class.

      Are you running TCPSvr.main() in a BackgroundWorke r? 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.T ext 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.t ext is in the class below?
      >
      cheers
      Dave
      >
      >
      >
      >
      >
      >
      "Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
      message news:4DADB054-66A2-4CAB-B49B-3A9A3E968DF6@mi crosoft.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.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

      • hb21l6

        #4
        Re: write response to textbox from a class.


        Yeah, its running as a seperate thread uwing backgroundWorke r.

        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" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
        message news:B2C1C9FD-8964-4BB4-97C1-2E992656C38D@mi crosoft.com...
        Are you running TCPSvr.main() in a BackgroundWorke r? 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.T ext 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" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
        >message news:4DADB054-66A2-4CAB-B49B-3A9A3E968DF6@mi crosoft.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.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.En coding.ASCII.Ge tBytes(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

        • hb21l6

          #5
          Re: write response to textbox from a class.

          it would appear that this is a common thing,




          I'll try to implement this, 'just like you said mike' and see if it solves
          the issue.

          Dave


          "hb21l6" <hb21l6@hotmail .comwrote in message
          news:865C5604-7DF2-40B0-9969-405AE1A706B4@mi crosoft.com...
          >
          Yeah, its running as a seperate thread uwing backgroundWorke r.
          >
          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" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
          message news:B2C1C9FD-8964-4BB4-97C1-2E992656C38D@mi crosoft.com...
          >Are you running TCPSvr.main() in a BackgroundWorke r? 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.T ext 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" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
          >>message news:4DADB054-66A2-4CAB-B49B-3A9A3E968DF6@mi crosoft.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.Tex t = "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.E ncoding.ASCII.G etBytes(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

          • Family Tree Mike

            #6
            Re: write response to textbox from a class.

            That was an interesting blog. Hopefully it gets you going.

            "hb21l6" <hb21l6@hotmail .comwrote in message
            news:A9E9C12B-7E6A-4CBB-BC9A-129FDD43BB03@mi crosoft.com...
            it would appear that this is a common thing,
            >

            >
            >
            I'll try to implement this, 'just like you said mike' and see if it solves
            the issue.
            >
            Dave
            >
            >
            "hb21l6" <hb21l6@hotmail .comwrote in message
            news:865C5604-7DF2-40B0-9969-405AE1A706B4@mi crosoft.com...
            >>
            >Yeah, its running as a seperate thread uwing backgroundWorke r.
            >>
            >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" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
            >message news:B2C1C9FD-8964-4BB4-97C1-2E992656C38D@mi crosoft.com...
            >>Are you running TCPSvr.main() in a BackgroundWorke r? 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.T ext 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_re c.text is in the class below?
            >>>>
            >>>cheers
            >>>Dave
            >>>>
            >>>>
            >>>>
            >>>>
            >>>>
            >>>>
            >>>"Family Tree Mike" <FamilyTreeMike @discussions.mi crosoft.comwrot e in
            >>>message news:4DADB054-66A2-4CAB-B49B-3A9A3E968DF6@mi crosoft.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.Te xt = "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.Pa rse("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. Encoding.ASCII. GetBytes(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

            Working...