Please Help with TCP

Soul 2.0

New member
Joined
Mar 7, 2006
Messages
2
Programming Experience
Beginner
VB.NET:
Imports System.Net
Imports System.Net.Sockets

Public Class Form1

#Region "Var"
    Const port As Int32 = 10000
    Private clients As New Hashtable()
    Private Server As TcpListener
    Private ipserv As IPAddress = IPAddress.Parse("192.168.1.3")
#End Region

    Friend Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Me.Update()
        Me.Close()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Server = New TcpListener(ipserv, port)
        Try
            Server.Start()
            Do
                Dim user As New info(Server.AcceptTcpClient)
            Loop Until True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

Public Class info
#Region "var"

    'Info sobre o cliente
    Dim user As TcpClient 'defeniçao do cliente
    Dim clienteIP As String 'Ip do Cliente
    Dim data() As Byte 'para receber os dados
    Public Shared AllC As New Hashtable '"Base de Dados"

#End Region
  

    Public Sub New(ByVal cliente As TcpClient)
        Try
            user = cliente
            clienteIP = cliente.Client.RemoteEndPoint.ToString 'Traduz o Ip do Cliente
            AllC.Add(clienteIP, Me) ' Adiciona o Cliente a "Base de Dados" 
            ReDim data(user.ReceiveBufferSize) ' Redimensiona o Array para receber os dados
            user.GetStream.BeginRead(data, 0, CInt(user.ReceiveBufferSize), AddressOf rsms, Nothing) ' Recebe os dados do cliente numa nova Thread
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Public Sub rsms(ByVal a As IAsyncResult)
        Dim tdados As Integer

        Try
            SyncLock user.GetStream
                tdados = user.GetStream.EndRead(a)
            End SyncLock
            If tdados < 1 Then
                UpdateStatus("O Cliente com o IP " & clienteIP & " deixou o Chat")
                Exit Sub
            Else
                Dim smsr As String = System.Text.Encoding.ASCII.GetString(data, 0, tdados)
                UpdateStatus(smsr)
            End If

            SyncLock user.GetStream
                user.GetStream.BeginRead(data, 0, CInt(user.ReceiveBufferSize), AddressOf rsms, Nothing)
            End SyncLock
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub UpdateStatus(ByVal statusMessage As String)
        Form1.TextBox1.Text = (statusMessage)
    End Sub

End Class


I have this code, and when execute, the textbox1 dont show the incoming data from client, why? i am new in this sry if my question in a stupid question, and sry about my English
 
i dont see you assigning anything to Textbox1 in your main form, so there shouldnt be anything displayed based on the code

in the Load Event you'll need to include lines such as:
Textbox1.Text = "whatever the data is"
or you can use:
Textbox1.AppendText("whatever the data is")

without more details on what exactly your code is doing, i dont know how to help ya further

i'm not familiar with network programming
 
JuggaloBrotha said:
i dont see you assigning anything to Textbox1 in your main form, so there shouldnt be anything displayed based on the code

I think that this function do that or not :confused:

VB.NET:
Private Sub UpdateStatus(ByVal statusMessage As String)
        Form1.TextBox1.Text = (statusMessage)
    End Sub
 
Back
Top