senddata method problem in winsock control 
Author Message
 senddata method problem in winsock control

I am a newbie in VB so please don't laugh. However, I am trying to write a
small client program to connect to another server through socket. I did this
by winsock control. However, it seems that I can not send data immediately
after connecting to the server. The following program never works. Am I
missing something here? Thanks.


Private Sub talk()

tcpClient.RemoteHost = "localhost"
tcpClient.RemotePort = 1400
tcpClient.Protocol = sckTCPProtocol


tcpClient.SendData "hello"

End Sub

Sun, 19 May 2002 03:00:00 GMT  
 senddata method problem in winsock control
You have to wait until the server on the other end has accepted the
connection.  Do this by trapping the Connect event.

Try this code.  You'll need a form with a multi-line text box, a winsock
control and a command button.  Pushing the button connects to port 80 of a
web server then (when the connection is established) it sends the correct
data to get a web page then displays the reults in the text box

Option Explicit

Private Sub Command1_Click()
Text1 = ""
Winsock1.Protocol = sckTCPProtocol
Winsock1.Connect "", 80

End Sub

Private Sub Winsock1_Connect()
Dim sText As String

    sText = "GET /default.asp HTTP/1.0" & vbCrLf & "Accept: text/html" &
vbCrLf & vbCrLf
    Winsock1.SendData sText
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sText As String

    On Error Resume Next
    Winsock1.GetData sText
    Text1 = Text1 & sText
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String,
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
    MsgBox Number & " - " & Description, vbCritical, App.Title
End Sub

Sun, 19 May 2002 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. SendData method for winsock control 6.0

2. winsock problem sending large strings (winsock.senddata)

3. how to send structures in winsock senddata method?

4. Winsock Senddata method - confusing?!

5. Winsock Senddata method - confusing?!

6. winsock senddata problem/question

7. Winsock.SendData Problem

8. problem with winsock.senddata

9. VB6: Winsock senddata problem - help!

10. Visual Basic Winsock senddata problem

11. WInsock SendData problem HELP

12. Winsock TCP SendData problem


Powered by phpBB® Forum Software