Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué

Post new topic   Reply to topic
winsock send data problem
View previous topic :: View next topic  
Author Message
collegegirly
Newbie


Joined: 17 Jan 2004
Posts: 2

PostPosted: Jan 17th, 2004 05:20 PM    Post subject: winsock send data problem Reply with quote

i am trying to send data from a client form to a server using winsock array on the server side. the problem i am having is i keep getting an error message - "40006 - wrong protocol or connection state for the requested transaction or request". However, the connection between the client and server is active. Is this a common problem? How would i overcome this?

This is the code i am using for the server;

Private Sub ws_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim Strdata As String
ws(Index).GetData Strdata, vbString
If ws(0).State <> 0 Then '& NewConnection(0)) = True Then

Dim UserName As String, Password As String
UserName = Left$(Strdata, 16)
UserName = Trim(UserName)
Password = Right$(Strdata, 16)
Password = Trim(Password)
Dim Flag As Boolean
Flag = False
Dim db As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim query As String
db.ConnectionString = "Data Source=cs;"
db.Open
Dim parameter As String
query = "SELECT user.UserName, user.Password From [user] WHERE (((user.UserName)='" & UserName & "') AND ((user.Password)='" & Password & "'));"
rec.Open query, db
On Error GoTo errorhandler
rec.MoveFirst

If rec.Fields("UserName").Value = UserName And rec.Fields("Password").Value = Password Then
Flag = True
NewConnection(0) = False
End If

db.Close


errorhandler:
Select Case Err.Number
Case 3021:
ws(0).SendData "False"
Exit Sub
End Select
If Flag = True Then

ws(0).SendData "True"
Else
If Flag = False Then
ws(0).SendData "False"
DoEvents
ws(0).Close
End If
End If

Else

Dim test As String

test = Strdata
x = 0
mypos = InStr(1, test, ",", 1)
Do
parser(x) = Left(test, mypos - 1)
test = Mid(test, mypos + 1, Len(test))
mypos = InStr(1, test, ",", 1)
x = x + 1
Loop Until mypos = 0
parser(x) = test

Call DatabaseChoice
' End If
End If

End Sub


This is the code i am using for the client side;

Private Sub Form_Load()
Dim databasechoice As String
ClientPort = 1
ws.Close
ws.LocalPort = ClientPort
ws.Connect lblIP.Caption, 1000 + ClientPort

ws.senddata databasechoice & "," & choice

The trouble is the second client connection that the server receives is not able to send data to the server and this is when we get the error above

Any suggestions would be welcome.
Back to top
View user's profile Send private message
P.T.A.M.
Administrator


Joined: 08 Oct 2003
Posts: 752
Location: Greece

PostPosted: Jan 18th, 2004 08:41 AM    Post subject: Reply with quote

You can check if a connection is established like this :

Code:
If Winsock1.State = sckConnected Then


but I don't think this will help much...

Does the client or the server show the error?
_________________
No one is completely useless. They can at least be an example of what to avoid.
Back to top
View user's profile Send private message Send e-mail Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic