|
-
Sep 8th, 2000, 09:05 PM
#1
Thread Starter
Lively Member
howcome when i try to connect with my winsock client... to my server, it keeps giving me a stupid error!!! it keeps saying invalide operation at current state!! error 40020
please respond fast!!!
client code
Option Explicit
Private Sub cmdConnect_Click()
On Error Resume Next
sock.Connect txtIP, txtPort
End Sub
Private Sub cmdDisconnect_Click()
sock.Close
End Sub
Private Sub sock_Connect()
MsgBox "hi", vbOKOnly, "hi"
End Sub
server code
Option Explicit
Private Sub Form_Load()
If sock.State <> sckClosed Then
sock.Close
End If
sock.Listen
End Sub
Private Sub sock_Connect()
MsgBox "hi", vbOKOnly, "hi"
End Sub
Private Sub sock_ConnectionRequest(ByVal requestID As Long)
sock.Accept requestID
End Sub
-
Sep 8th, 2000, 09:38 PM
#2
Addicted Member
You will get this error if you have the winsock control listening to a port when you used connect method.
To allow multiple clients to connect to the server you must have an array of winsock controls in the server program. The code should be as follows:
Dim i as integer, a() As String, b() as String
Sub Form_Load()
wsc(0).LocalPort = 23
wsc(0).Listen
End Sub
Sub wsc_ConnectionRequest(Index as Integer, RequestId as Integer)
If Index <> 0 Then
i = i + 1
Redim Preserve a(i)
Redim Preserve b(i)
Load wsc(i)
wsc(i).Accept RequestID
End If
End Sub
Sub wsc_DataArrival(Index as Integer)
wsc(Index).GetData a(Index)
End Sub
Sub SendData(Param As String)
b(Index) = Param
wsc(Index).SendData b(Index)
End Sub
There might be errors because I have not tested the code yet. Give it a go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|