|
-
Aug 13th, 2001, 05:02 PM
#1
Thread Starter
Fanatic Member
Winsock arrrggg (PLEASE HELP)
Okay I have been battling away for some time trying to get a winsock connection working within my app.
I have written previous apps using the same code and it has worked fine. But now all I get is either "Address in Use Error" or if I change the ports to be 0 to let winsock determine the port I simple get nothing this is driving me insane
Here is the code im using
VB Code:
Private Sub Form_Activate()
Dim strIp As String
If isLoaded = False Then
strIp = SckListen(0).LocalIP
SckListen(0).LocalPort = 1001
SckListen(0).Listen
objData.addChatUser User, strIp
If isDemo = True Then
demoValidate
End If
isLoaded = True
End If
End Sub
Private Sub SckListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If SckListen(0).State <> sckClosed Then SckListen(0).Close
If Index = 0 Then
intSckIndex = intSckIndex + 1
Load SckListen(intSckIndex)
SckListen(intSckIndex).LocalPort = 0
SckListen(intSckIndex).Accept requestID
End If
End Sub
'In another form
Private Sub cmdChat_Click()
Dim txtSelected
Dim intCount As Integer
Dim isSel As Boolean
Dim strSend As String
Dim strChatName As String
Dim strHost As String
Dim isConnect As Boolean
isSel = False
For intCount = 0 To List1.ListCount - 1
If List1.Selected(intCount) = True Then
isSel = True
End If
Next intCount
If isSel = False Then
msg = MsgBox("Please Select a user!", vbInformation)
Exit Sub
End If
Set frmChat = New frmClientChat
intFrmChatCount = FrmChatCol.count + 1
strChatName = User & " Session " & intFrmChatCount
frmChat.Tag = strChatName
FrmChatCol.Add frmChat, frmChat.Tag
For intCount = 0 To List1.ListCount - 1
If List1.Selected(intCount) = True Then
intSckIndex = intSckIndex + 1
Load frmDesktop.SckListen(intSckIndex)
strHost = objData.getChatHost(List1.List(intCount))
frmDesktop.SckListen(intSckIndex).Connect strHost, 1001
If frmDesktop.SckListen(intSckIndex).State = sckConnected Then
strSend = "REQUEST" & Chr$(182) & User & Chr$(182) & strChatName
frmDesktop.SckListen(intSckIndex).SendData strSend
End If
End If
Next intCount
frmChat.Show
Unload Me
End Sub
that last sub is little dodgy now as I have been playing around with it trying out different stuff
Can someone anyone please help me sort this out ??
Thanks
PS sorry for reposting this question but I need to resolve it asap as it is holding up my entire project now
-
Aug 13th, 2001, 06:00 PM
#2
PowerPoster
Quick question rudvs2 without really looking to indepth at the code arre you trying to listen and "talk"/send at the same time on the same winsock control? Or soemthing similar.
I had that problem and i found it but creating 2 different apps one listener and one sender. Then worked backwards.
Just a suggestion!
-
Aug 13th, 2001, 06:06 PM
#3
Thread Starter
Fanatic Member
Hmm I havent tried the two seperate apps yet but I have got it creating a control array so there is only 1 winsock control that is always listening then it adds controls as connection requests come in.
-
Aug 13th, 2001, 06:15 PM
#4
PowerPoster
Try it!
It is microsoft after all!
You never know!
-
Aug 13th, 2001, 09:06 PM
#5
I only took a quick look but isn't this closing your main listening sock.
VB Code:
If SckListen(0).State <> sckClosed Then SckListen(0).Close
-
Aug 13th, 2001, 09:14 PM
#6
Thread Starter
Fanatic Member
yeah it does
I only threw that in there to try something out
The error occurs without that line
PS I still cant get the damn thing working
-
Aug 14th, 2001, 12:15 AM
#7
Is the 'client' and 'server' both members of the SckListen winsock array? Whats the point of that?
Don't you want your array to be the 'server' and a single sock for the 'client'? The frmDesktop.SckListen(intSckIndex).Connect strHost, 1001 confuses me.
Are you making a chat app? I just redid you I made awhile ago. Let me know if you want to trade notes, code, whatever.
-
Aug 14th, 2001, 05:47 AM
#8
Fanatic Member
Info.
The LocalPort property is being set to 0 for new instances of the winsock control.
For servers, this defines the port for which a connection listens on. If the client assumes the remote port is 1001 (which it connects on in your example), then the client will try and send data to port 1001... yet the local port of the server is set to 0 (or random) when a connection request occurs... This might explain why you're not recieving data.
Try not setting the local port property of new instances in the connection request event to 0. i.e.
VB Code:
Private Sub SckListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intSckIndex = intSckIndex + 1
Load SckListen(intSckIndex)
'Check to see if we're closed.
If SckListen(intSckIndex).State <> sckClosed Then
SckListen(intSckIndex).Close
DoEvents
End If
'Accept.
SckListen(intSckIndex).Accept requestID
End If
End Sub
This will accept connections on port 1001. The local port properties for new controls loaded at runtime will also be 1001.
It might be an idea to try coding seperate server/client projects. It will make things easier to deal with.
Hope this helps.
Laterz
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Aug 15th, 2001, 06:15 PM
#9
Thread Starter
Fanatic Member
Edneeis
The reason I am trying to do it all from an array is and I do not want to create seperate server client apps is because this is an extra feature in another app i am writing. The users will be able to see who is logged on via a central database that is updated when they run this application.
I want multiple chat sessions to be able to take place IE the user can recieve a chat request and start a conversation. Then the user can opt to also create another chat with another users or invite others into your exsisting chat. Much like all the chat apps work.
I thought in theory what I am trying to do should work. But I guess im wrong there
PS I would be glad to trade notes as I really have to resolve this and get something happening very very quickly now.
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
|