Results 1 to 5 of 5

Thread: Socket Help! Winsock was so much easier!

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    32

    Socket Help! Winsock was so much easier!

    I can create a connection, but I can't send nor receive data.
    Code:
        Private tcpClient As tcpClient
        Private tcpListener As tcpListener
    
        Private Function DisplayText(ByVal TextToAdd As String)
            txtDisplay.AppendText(TextToAdd + vbCrLf)
        End Function
    
        Private Sub txtInput_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtInput.KeyUp
            If e.KeyCode = Keys.Enter And txtInput.Text <> "" Then
                DisplayText(txtInput.Text)
                txtInput.Text = ""
            End If
        End Sub
    
        Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
            Me.Text = "Client"
            Try
                tcpClient = New TcpClient()
                tcpClient.Connect("127.0.0.1", 1337)
    
                DisplayText("Connection established")
            Catch ex As Exception
                DisplayText(ex.ToString)
            End Try
        End Sub
    
        Dim message As String = "wahahahaha"
    
        Private Sub btnListen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnListen.Click
            Me.Text = "Server"
            Try
                DisplayText("Waiting for connection...")
    
                tcpListener = New TcpListener(System.Net.IPAddress.Parse("127.0.0.1"), 1337)
                tcpListener.Start()
    
                Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
    
                DisplayText("Connection established")
            Catch ex As Exception
                DisplayText(ex.ToString)
            End Try
        End Sub

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    32
    :bump:

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    32
    Deadline for the project is 2 days time and I yet to finish it, anyone to the rescue? Need a application than can act as a client AND a server which a click of a button. Using .NET sockets.

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    32
    bump

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Late to the party, guess your deadline passed by now, but...

    I don't see anywhere in your code where you try to send data. Maybe do a tcpClient.Send.

    Check the built in help for basic working examples.

    I'm trying to write a Windows Service that connects to one server and multiple clients connect to it. Haven't got it down yet, but the starting code was taken from the help. This app was written and works fine in VB6, trying to port to .NET service. I agree that it was easier (faster) with the Winsock control. Gives me something to do, anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width