Results 1 to 6 of 6

Thread: [RESOLVED] Winsock problem with sending data

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    108

    [RESOLVED] Winsock problem with sending data

    Hi, I've been browsing these forums (and some others) and I have yet to find a solution to my problem so I decided to sign up and post a thread. I'm really new to VB, been doing this for two days to be honest I'm using Visual Basic 2005 Express Edition to do the program.

    My program is for the moment just a really simple chatprogram (just trying to learn here you know), but in the end it will end up as (I hope) a program to connect to a device using telnet and be able to change and view the settings for the device. (The device currently has to be configure manually through telnet).

    I use "my" program and another one called SimpleChat by Dave Dunghill. The SimpleChat program had to be updated in order for VB to open and run it (dont know if it got messed up somewhere on the way).

    The problem is that neither program is sending or receiving data from the other. Even if I run two copies of the chatprogram by Dave no data is sent (doesn't show up in the textbox anyway). Both programs indicate that they are connected after I tried to connect them.

    I also tried to install the chatprogram by Dave onto my home computer to see if it would work (by using the Publish function and set it to be installed from CD/DVD). It downloaded and installed .NET Frameworks 2 on my computer but the program itself wont start. First time I tried it put itself in the Start-meny, but after several tries it din't even do that anymore.

    I'd be grateful if someone could please help me with this

    This is the program I've put together (copy/paste mostly )

    VB Code:
    1. Option Strict Off
    2. Option Explicit On
    3. Friend Class Form1
    4.     Inherits System.Windows.Forms.Form
    5.  
    6.     Private Sub buttonConnect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles buttonConnect.Click
    7.  
    8.         ' reset the socket
    9.         Winsock.Close()
    10.  
    11.         ' set the new properties
    12.         Winsock.RemoteHost = "localhost" 'I put localhost here just now instead of my real IP
    13.         Winsock.RemotePort = "1234"
    14.  
    15.         ' initiate the connection
    16.         txtMain.Text = txtMain.Text & vbCrLf & "Connecting to " & comboDSLAM.Text & "..."
    17.         Winsock.Connect()
    18.  
    19.     End Sub
    20.  
    21.     Private Sub cmdSend_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles buttonSend.Click
    22.         ' make sure we're connected
    23.         If Winsock.CtlState = MSWinsockLib.StateConstants.sckConnected Then
    24.             ' send the data
    25.             Winsock.SendData(txtCommand.Text & vbCrLf)
    26.             System.Windows.Forms.Application.DoEvents()
    27.             ' log the data in the main window
    28.             LogData(txtCommand.Text)
    29.             ' clear the text ready for the next command
    30.             txtCommand.Text = ""
    31.         Else
    32.             txtMain.Text = txtMain.Text & vbCrLf & "You're not connected to anything"
    33.         End If
    34.     End Sub
    35.  
    36.     Private Sub Winsock_ConnectEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Winsock.ConnectEvent
    37.         ' alert the user that we're connected
    38.         txtMain.Text = txtMain.Text & vbCrLf & "Connection established to " & Winsock.RemoteHostIP
    39.     End Sub
    40.  
    41.     Private Sub Winsock_CloseEvent(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Winsock.CloseEvent
    42.         ' alert the user when disconnected
    43.         txtMain.Text = txtMain.Text & vbCrLf & "The connection to " & comboDSLAM.Text & " (" & Winsock.RemoteHostIP & ") has been terminated"
    44.     End Sub
    45.  
    46.     Private Sub Winsock_DataArrival(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles Winsock.DataArrival
    47.         Dim strData As String
    48.         ' get the data
    49.         Winsock.GetData(strData)
    50.         ' display it in the main textbox
    51.         LogData(strData)
    52.  
    53.     End Sub
    54.  
    55.     Private Sub Winsock_Error(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent) Handles Winsock.Error
    56.         ' alert the user to the error
    57.         txtMain.Text = txtMain.Text & vbCrLf & "Error: " & eventArgs.description
    58.     End Sub
    59.  
    60.     Private Sub LogData(ByVal strData As String)
    61.         ' add string to the end of the textbox
    62.         txtMain.Text = txtMain.Text & vbCrLf & strData
    63.         ' scroll the textbox down
    64.         txtMain.SelectionStart = Len(txtMain.Text)
    65.     End Sub
    66.  
    67.     Private Sub Form_Unload(ByVal Cancel As Integer)
    68.         Winsock.Close()
    69.     End Sub
    70.  
    71. End Class
    Last edited by Darkstorm; Jan 5th, 2006 at 03:03 AM.

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