|
-
Mar 11th, 2003, 05:19 AM
#1
[RESOLVED] Winsock wont connect (Resolved)
I am having a problem with winsock in my app, I can connect to the sever when I test it using my demo but when I use the actual application it wont connect. Below is the code I am using to connect to the server:
VB Code:
Private Sub Command2_Click()
messcon.Connect txtConnect, 7000
If messcon.State = sckConnected Then
Command2.Enabled = False
Else
MsgBox (LoadResString(68 + i))
End If
End Sub
I keep getting the please connect message showing up. It worked find before I added this code:
VB Code:
Private Sub Command3_Click()
If Not txtAttachment.Text = "" Then
NF = FreeFile
Open cmdAttach.FileName For Input As #NF
Input #NF, data
fname = cmdAttach.FileTitle
messcon.SendData "|DATA|" & data & fname
Close #NF
End If
End Sub
Private Sub Messlis_DataArrival(Index As Integer, ByVal bytesTotal As Long)
If InStr(1, str, "|DATA|") <> 0 Then
NF = FreeFile
MkDir (App.Path & "\Received Files\")
Open App.Path & "\Received Files\" & fname For Output As #NF
Print #NF, data
Close #NF
End If
End Sub
TIA
Nightwalker83
Last edited by Nightwalker83; Mar 13th, 2003 at 06:30 PM.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 11th, 2003, 05:33 AM
#2
Frenzied Member
What protocol u r using? and what is the description of error.....?
please elaborate!
-
Mar 11th, 2003, 05:45 AM
#3
1. TCP Protocol
2. It's not an error message just a message thats part of my application.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 11th, 2003, 05:59 AM
#4
Frenzied Member
Still not enough information to reach to any conclusion...
well.. if using TCP, have u made another winsock listening to your connect request? and also.. the winsock which is in listening mode cannot accept the connection request..
-
Mar 11th, 2003, 06:10 AM
#5
VB Code:
Private Sub Form_Load()
On Error Resume Next
intmax = 0
Messlis(intmax).LocalPort = 7000
Messlis(intmax).Listen
End Sub
This is the code I am using for the connection request:
VB Code:
Private Sub Messlis_ConnectionRequest(Index As Integer, ByVal requestID As Long)
'Allow the chat app to accept more than one connection
If Index = 0 Then
intmax = intmax + 1
Load Messlis(intmax)
Messlis(intmax).Accept requestID
End If
If Messlis(intmax).State = sckError Then
MsgBox (LoadResString(67 + i))
End If
End Sub
This code was working before so I don't think this is the problem since I didn't change it.
Last edited by Nightwalker83; Mar 11th, 2003 at 06:16 AM.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 11th, 2003, 06:14 AM
#6
Frenzied Member
and the code in ConnectionRequest event...Where u are accepting the request...????
-
Mar 11th, 2003, 06:17 AM
#7
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 11th, 2003, 09:36 AM
#8
KING BODWAD XXI
-
Mar 11th, 2003, 09:42 AM
#9
Junior Member
What is the error message?
The arrow shot by the archer may, or may not, kill a single person. However, stratagems devised by a wise man, can kill even babes in the womb.
-
Mar 11th, 2003, 07:36 PM
#10
Addicted Member
He has one winsock control listening (index = 0) and then he creates a new winsock control for every new user. -Note: You don't have to use something like intMax, just use messlis.UBound when creating new winsock controls-
However, as described on winsockvb.com, you are going to have to create a boolean array along with your winsock controls, and replace your code with this under connection_request.
Code:
for i = messlis.LBound to messlis.ubound
if Connection(i) = False then 'There is an empty winsock control..
messliss(i).accept requestID
connection(i) = true 'Set the boolean to true, it is taken
exit sub
end if
next i
If Index = 0 Then
intmax = intmax + 1
Load Messlis(intmax)
Messlis(intmax).Accept requestID
End If
-
Mar 11th, 2003, 09:05 PM
#11
Originally posted by jeb2022
Code:
for i = messlis.LBound to messlis.ubound
if Connection(i) = False then 'There is an empty winsock control..
messliss(i).accept requestID
connection(i) = true 'Set the boolean to true, it is taken
exit sub
end if
next i
I tried this code but it up with a Sub or Function not defined error on this line:
VB Code:
if Connection(i) = False then
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 12th, 2003, 03:10 AM
#12
KING BODWAD XXI
Private Connection(200) as boolean
This will just inform your app as to wether your winsock is in use.
you need to check through all currently loaded winsocks to see if they have a connection established, if not then the user on that winsock has left and it is free for use. The boolean indicates which are in use and which are not.
-
Mar 12th, 2003, 03:20 AM
#13
KING BODWAD XXI
-
Mar 12th, 2003, 03:25 AM
#14
The statements after connect were probably immediately fired before the connection negotiation finished. I had the same problem and I also return a value (boolean in my case), you can also try something like this.
VB Code:
'blah blah
Attempt_Connect:
frmCommon.sckTCP(SocketIndex).Close
frmCommon.sckTCP(SocketIndex).LocalPort = 0
On Error GoTo Error_Handler
frmCommon.sckTCP(SocketIndex).Connect Trim(strIPAddress) 'Connect attempt
On Error GoTo 0
Count_Pause = 0
Do Until Count_Pause >= MAX_Retry
If frmCommon.sckTCP(SocketIndex).State = sckConnected Then
Count_Pause = MAX_Retry
Else
Call Pause(15)
Count_Pause = Count_Pause + 1
End If
Loop
If frmCommon.sckTCP(SocketIndex).State <> sckConnected Then
GoTo Error_Handler 'Retry connecting while Count_Connect < 3
End If
ConnectSocket_sckTCP = True
GoTo Exit_Proc
Error_Handler:
Count_Connect = Count_Connect + 1
If Count_Connect >= MAX_Retry Then
'blah blah
GoTo Exit_Proc
Else
GoTo Attempt_Connect 'Retry connect.
End If
Exit_Proc:
End Function
BTW, I used Exit_Proc because is still had some statements which I did not include here. Essentially, you do a loop, up to three times, to check the state of the socket.
Pause() is a user defined pause using GetTickCount with DoEvents in it. I noticed that when I set pause to 10 milliseconds the loop occurs twice before the socket state becomes connected. When I changed it to 15 milliseconds, I passed through the loop only once.
Last edited by leinad31; Mar 12th, 2003 at 03:30 AM.
-
Mar 12th, 2003, 03:41 AM
#15
-
Mar 12th, 2003, 03:42 AM
#16
Actually, the Connect event fires first. But I went to the trouble of the loop so that my Connect_sckTCP() procedure will return a correct value. Here's an excerpt from the procedure trace I did:
16:31:57 - 0000000014 START ConnectSocket_sckTCP(1, 202.81.179.144).[/B]
16:31:57 - 0000000015 START CheckIfExist_sckTCP(1, ).
16:31:57 - 0000000016 RETURNED CheckIfExist_sckTCP(1, ) = 1
16:31:57 - 0000000017 CONNECT frmCommon.sckTCP(1) TO 202.81.179.144 'This is right before I use connect method.
16:31:57 - 0000000018 START Pause(15).
16:31:57 - 0000000019 START frmCommon.sckTCP_Connect(1). 'This is the Winsock event.
.
.
frmCommon.sckTCP_ConnectionRequest(0, 1040). 'Because I did a loop connect.
.
.
16:31:57 - 0000000041 RETURNED ConnectSocket_sckTCP = True
Last edited by leinad31; Mar 12th, 2003 at 03:45 AM.
-
Mar 12th, 2003, 03:48 AM
#17
I replaced the code you mentioned with:
VB Code:
Private Sub Command2_Click()
messcon.Connect txtConnect, 7000
If messcon.State = sckConnected Then
Command2.Enabled = False
Else
Exit Sub
End If
End Sub
My prog seem to work fine now.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 12th, 2003, 03:49 AM
#18
Originally posted by BodwadUK
This will not work for slow connections (post Above)
you are both making it more complicated than neccassary
When using winsock ensure you have Service Pack 5 Installed for VB
True, but I'll be using it only on a LAN. Besides, my app needs a fast connection so if didn't connect because of the lag then its not worth connecting anyway. The slow connect will defeat the purpose.
-
Mar 12th, 2003, 03:55 AM
#19
Originally posted by Nightwalker83
I replaced the code you mentioned with:
VB Code:
Private Sub Command2_Click()
messcon.Connect txtConnect, 7000
If messcon.State = sckConnected Then
Command2.Enabled = False
Else
Exit Sub
End If
End Sub
My prog seem to work fine now.
You can just as well replace it with:
VB Code:
Private Sub Command2_Click()
messcon.Connect txtConnect, 7000
End Sub
because there is no way the socket connects that fast that you can check for it in the next line of code. Not even in a LAN.
If you want to disable Command1 after the connection succeeded use something like:
VB Code:
Private Sub messcon_Connect()
Command1.Enabled = False
End Sub
-
Mar 12th, 2003, 04:49 AM
#20
Originally posted by Frans C
You can just as well replace it with:
VB Code:
Private Sub Command2_Click()
messcon.Connect txtConnect, 7000
End Sub
because there is no way the socket connects that fast that you can check for it in the next line of code. Not even in a LAN.
If you want to disable Command1 after the connection succeeded use something like:
VB Code:
Private Sub messcon_Connect()
Command1.Enabled = False
End Sub
That code isn't working.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 12th, 2003, 04:59 AM
#21
KING BODWAD XXI
-
Mar 12th, 2003, 05:01 AM
#22
Nope
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 12th, 2003, 07:46 AM
#23
-
Mar 13th, 2003, 03:46 AM
#24
Yes as I said it was working before prefectly alright before I made the changes. I didn't not change anything in the Messcon or Messlis connection events so I don't know what the problem could be.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 13th, 2003, 04:22 AM
#25
PowerPoster
Doevents maybe? 
You'd be surprised how many times that can solve a problem.
-
Mar 13th, 2003, 04:51 AM
#26
Originally posted by Pc_Madness
Doevents maybe? 
You'd be surprised how many times that can solve a problem.
You'de be surprised how many times it can CAUSE a problem as well, especially if you use it in winsock events (DataArrival for instance).
-
Mar 13th, 2003, 11:41 AM
#27
I tried your app and the connection works fine. Only change I made was remove the code that disabled the connect button if the entered IP address is equal to the localIP. That way I could do a local connect and it worked fine except for the popping message.
The message pops up because you immediately did a compare on the socket state though it hasn't changed yet. But when I checked the state of the socket it was already connected and I could send messages.
-
Mar 13th, 2003, 06:23 PM
#28
Originally posted by leinad31
I tried your app and the connection works fine. Only change I made was remove the code that disabled the connect button if the entered IP address is equal to the localIP. That way I could do a local connect and it worked fine except for the popping message.
I removed the following code and it seems to be working.
VB Code:
If txtConnect.Text = messcon.LocalIP Then
Command2.Enabled = False
Command4.Enabled = False
Else
Command2.Enabled = True
Command4.Enabled = True
End If
The message pops up because you immediately did a compare on the socket state though it hasn't changed yet. But when I checked the state of the socket it was already connected and I could send messages.
Yeah I used this code to check for the connection state:
VB Code:
Private Sub Timer2_Timer()
Select Case messcon.State
Case "7"
Me.Caption = Me.Caption & " - Connected"
Case "8"
Me.Caption = Me.Caption & " - Connection was closed"
End Select
End Sub
I had all the connection states but Messcon proberly wouldn't have encounted them.
Last edited by Nightwalker83; Nov 16th, 2003 at 07:24 PM.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
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
|