|
-
Aug 20th, 2000, 09:25 AM
#1
Thread Starter
Frenzied Member
I'm trying to send data between to computer using the WinSock Control! But it doesn't work!
I'm trying to send the data in a textfield(SendData) to another computer on the network, but I get the following error:
Run-Time error: 40006
Wrong Protocol or connection state for the requested transaction or request.
What's wrong here!?
-
Aug 20th, 2000, 01:02 PM
#2
Junior Member
The problem is that you're not connected to the computer you're trying to send data to. You can check this by typing this in before you send the data, Debug.Print (name of winsock control here).State. If it does not print 7, then you are not connected.
Here is what all the state numbers mean:
sckClosed 0 Default. Closed
sckOpen 1 Open
sckListening 2 Listening
sckConnectionPending 3 Connection pending
sckResolvingHost 4 Resolving host
sckHostResolved 5 Host resolved
sckConnecting 6 Connecting
sckConnected 7 Connected
sckClosing 8 Peer is closing the connection
sckError 9 Error
-
Aug 20th, 2000, 01:06 PM
#3
Frenzied Member
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Accept requestID
End Sub
-
Aug 20th, 2000, 01:41 PM
#4
Thread Starter
Frenzied Member
The Winsock state is 0
How can i make go 7???
-
Aug 21st, 2000, 06:06 PM
#5
Junior Member
The Visual Basic help file shows you how to use the winsock control.
-
Aug 21st, 2000, 06:11 PM
#6
So Unbanned
The winsock control you're going to connect to must be listening for it:
Winsock1.Listen
Make sure it's local port is that of the other winsocks remote port. And you have the address, all the required stuff. Then call:
Winsock1.Connect
Then in your winsock_connect function type something like:
Form1.Caption = "Connected"
Or:
check if the state is 7 before you send stuff
If winsock1.state <> 7 then exit sub
'data here
-
Aug 22nd, 2000, 03:21 AM
#7
Frenzied Member
Add two buttons and two textboxes to 1 form, name one text box txtIP and the other txtData, next name one Button cmdSend and the other cmdConnect. Here is the code for the CLIENT::
Private Sub cmdConnect_Click()
Winsock1.Connect txtIP.Text, 1234
End Sub
Private Sub Winsock1_Connect()
Me.Caption = "Connected"
End Sub
Private Sub cmdSend_Click()
Winsock1.SendData txtData.Text
End Sub
For the server add a textbox to the form called txtData and a button call cmdListen. Here is the code for the SERVER::
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData, vbString
txtData.Text = strData
End Sub
Private Sub cmdListen_Click()
Winsock1.LocalPort = 1234
Winsock1.Listen
End Sub
This shoud do it for you to send data from one pc to another.
-
Aug 23rd, 2000, 06:22 AM
#8
Thread Starter
Frenzied Member
It still doesn't work....
The winsock state is 6....it never goes 7
-
Aug 23rd, 2000, 08:02 AM
#9
It'd be better if you post your code (both server and client), that way we can find the problem rather than guess what it might be.
Sunny
-
Aug 23rd, 2000, 10:50 AM
#10
Frenzied Member
I'll send you a demo app if you give me your email address
-
Aug 23rd, 2000, 05:23 PM
#11
Thread Starter
Frenzied Member
-
Aug 23rd, 2000, 05:26 PM
#12
Thread Starter
Frenzied Member
Client code
Code:
Private Sub cmdConnect_Click()
Winsock1.Connect txtIP.Text, 1234
Debug.Print Winsock1.State
End Sub
Private Sub cmdSend_Click()
Winsock1.SendData txtData.Text
End Sub
Private Sub Winsock1_Connect()
Me.Caption = "Connected"
End Sub
Server code:
Code:
Private Sub cmdListen_Click()
Winsock1.LocalPort = 1234
Winsock1.Listen
End Sub
Private Sub Form_Load()
Winsock1.LocalPort = 1234
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Accept requestID
Winsock1.Bind
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData, vbString
txtData.Text = strData
End Sub
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
|