CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    Send Socket Call

    Code:
    Imports System.Net.Sockets
    
    Public Class Form1
    
        Dim socket As New System.Net.Sockets.TcpClient
        Dim send As Byte()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            socket.Connect("66.226.73.112", 7705)
            send = System.Text.Encoding.ASCII.GetBytes("\R\N")
            socket.Client.Send(send)
            Recv.Text += socket.Client.Receive(send).ToString & vbNewLine
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            send = System.Text.Encoding.ASCII.GetBytes(TxtToSend.Text & "\R\N")
            socket.Client.Send(send)
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Recv.Text += socket.Client.Receive(send).ToString & vbNewLine
        End Sub
    End Class
    For some reason, it stops on the recv call and when I put a check for socket.client.available being greater than 0 it never gets anything. So the problem is that i'm not receiving any data. Is there any reason why?
    Microsoft Visual Basic 2008 Express Edition
    .NET Framwork 3.5 Beta SP1

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Send Socket Call

    First problem is that you are blocking inside of your Form_Load......
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jun 2007
    Location
    .NET 3.5 Beta SP1, Visual Basic 2008 Express
    Posts
    225

    Re: Send Socket Call

    Code:
    Imports System.Net.Sockets
    
    Public Class Form1
    
        Dim socket As New System.Net.Sockets.TcpClient
        Dim send As Byte()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            socket.Connect("66.226.73.112", 7705)
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            send = System.Text.Encoding.ASCII.GetBytes(TxtToSend.Text & "\R\N")
            socket.Client.Send(send)
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            While socket.Client.Available <> 0
                Recv.Text += socket.Client.Receive(send).ToString & vbNewLine
            End While
        End Sub
    End Class
    I modified it in this way. However, now socket.client.available is never greater than 0. I know that the host and port should send something because telnet gets something.
    Microsoft Visual Basic 2008 Express Edition
    .NET Framwork 3.5 Beta SP1

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Send Socket Call

    Why are you using a timer....use the proper events of the Socket class!!!!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

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

Featured