Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB6 Winsock Mystery


  • Please log in to reply

#1
machiefacro

machiefacro

    New Member

  • Member
  • Pip
  • 2 posts
I am really just picking up VB6, so if I seem like I have no idea what is happening, you'll know why. I've been working on this program that uses the Winsock functions to send some text over to other computers (20) and executes it as a batch file. Simple enough. I have the basics set up. I can connect to the server, send some text, and close the connection fine. So far I can do what I wanted. I have been following this tutorial : http://www.developer...k/show/1845/4/ . For the client portion it says to make three buttons, Connect, send, and close buttons. This is what I have on MY program. But because of the nature of what I am going to be doing, I need to have one button.

When I put the open, send, and close commands all under one button it does not seem to work. It opens the connect, waits a second, then closes it without any data being sent. I thought it might have been working too fast for the server to handle it, but I put a 3 second pause in there and it still didn't work.

Here is what I have now (working).
Private Sub connect_Click()
Winsock1.RemoteHost = editIPs.ip1.Text
Winsock1.RemotePort = 1007
Winsock1.Protocol = sckUDPProtocol
Winsock1.connect
End Sub

Private Sub discon_Click()
Winsock1.Close
End Sub

Private Sub senddata_Click()
Dim commands
'commands = Replace(commandsBox.Text, vbCrLf, "&")
commands = "dir&pause" 'for testing
Winsock1.senddata commands
End Sub

...and this is what I REALLY want...

Private Sub sendbutton_Click()
Dim commands
'commands = Replace(commandsBox.Text, vbCrLf, "&")
commands = "dir&pause"

Winsock1.RemoteHost = editIPs.ip1.Text
Winsock1.RemotePort = "1007"
Winsock1.Protocol = sckUDPProtocol
Winsock1.connect
Winsock1.senddata commands
Winsock1.Close

End Sub

This must be something easy, something I just missed. And I know someone has come across this problem before. Any help/ideas is appreciated.

Edited by machiefacro, 22 June 2005 - 12:31 AM.

  • 0

Advertisements


#2
v_mr_3

v_mr_3

    New Member

  • Member
  • Pip
  • 1 posts
Umm i havent tested this but the problem is the connect method takes some time and processes the next couple of commands before it is connected.
try using DOEVENTS or something like

Do
DoEvents
Loop Until Winsock1.State = sckConnected

Let me know if i have been of any help. thanks
[email protected]
  • 0

#3
FrOzeN

FrOzeN

    New Member

  • Member
  • Pip
  • 6 posts
Well that tutorial is on TCP/IP and you have yours as UDP.
Then host can't use .Listen when it's UDP.

I made a simply program for you, attached.

First compile them both to .exe's, then load the "Winsock Host Demo.exe".
Then you can open as many "Winsock Client Demo.exe's" as you like, and Connect them.
It is a basic Chat Program.

If you wanted to make the Client's receive one another's messages too.

Add this code to the 'Winsock Host Demo' project.
Replace the Sub:
Private Sub wsHost_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim strData As String
    wsHost(Index).GetData strData, vbString
        'Put the data received into a string
    DisplayText "<" & wsHost(Index).LocalIP & "(" & Index & ")> " & strData
        'Display the data
End Sub

With:
Private Sub wsHost_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim strData As String
    wsHost(Index).GetData strData, vbString
        'Put the data received into a string
    DisplayText "<" & wsHost(Index).LocalIP & "(" & Index & ")> " & strData
        'Display the data

    If intClients < 2 Then Exit Sub
        'Exit Sub if there arn't any other clients to send the message to
    Dim i As Integer
    For i = 1 To wsHost.Count - 1
        If (Len(wsHost(i).Tag) = 0) And (i <> Index) Then
            wsHost(i).SendData "(" & wsHost(Index).LocalIP & "[" & Index & "]) " & strData
                'Send Message to Client
        End If
    Next i
End Sub

The entire 2 projects are commented.

Hope this helps you with Winsock. :tazz:
For more information on winsock goto: http://www.winsockvb.com/

- FrOzeN

Attached Files


  • 0

#4
machiefacro

machiefacro

    New Member

  • Topic Starter
  • Member
  • Pip
  • 2 posts
Cool! Thanks for all the help with that!
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP