|
-
Apr 12th, 2005, 05:21 PM
#1
Thread Starter
Fanatic Member
First piece of data not sending?
Ok, I have a constantly open port which the client connects to, and then is redirected to a new socket. This works fine, but when I set up this new connection, I want to send the index of my winsock array back to the client, which I do right after the .accept method, but it doesn't send (or it isn't received, can't really tell which). I'm making sure they're connected before executing this, and all other instances of senddata work fine after, what's wrong?
-
Apr 13th, 2005, 10:50 AM
#2
Frenzied Member
Re: First piece of data not sending?
Most likely, you are sending the data before the connection process has finished. I would try using the Connect event to send the index. Personally, I have never tried using the Connect event on the server side because my servers do not send anything immediately after connecting. They only respond to requests from the client(s).
I'm curious as to why you are sending the client the index of the winsock control. Are you, perhaps, under the impression that the client needs to know which control it is connected to?
If you do in fact need to send the index, try this:
VB Code:
Private Sub Winsock1_Connect(Index As Integer)
Winsock1.SendData Index
End Sub
It will fire when the connection has completed for the control indicated by the value of Index.
-
Apr 13th, 2005, 04:41 PM
#3
Thread Starter
Fanatic Member
Re: First piece of data not sending?
Sorry, that doesn't work either.
-
Apr 13th, 2005, 04:55 PM
#4
Thread Starter
Fanatic Member
Re: First piece of data not sending?
In fact, my _connect method isn't even invoked.
Can you see anything wrong with my code?
VB Code:
Private Sub sckSendConnection_ConnectionRequest(ByVal requestID As Long)
sckSendConnection.Close
Dim I As Integer
For I = 0 To sckConnections.UBound - 1
If sckConnections(I).State = sckListening Then
sckConnections(I).Close
sckConnections(I).Accept requestID
sckSendConnection.Listen
Exit Sub
End If
Next I
Load sckConnections(sckConnections.UBound + 1)
I = sckConnections.UBound - 1
sckConnections(I + 1).LocalPort = sckConnections(I).LocalPort + 1
sckConnections(I + 1).Listen
sckConnections(I).Close
sckConnections(I).Accept requestID
Do Until sckConnections(I).State = sckConnected
DoEvents
Loop
sckSendConnection.Listen
End Sub
-
Apr 13th, 2005, 06:59 PM
#5
Frenzied Member
Re: First piece of data not sending?
I have to confess that I have never seen anyone try to do what you are doing. I'm not sure it is even going to work. It looks like you have a single listener (sckSendConnection) and an array of winsock controls, all of which may or may not be listening as well. I'm really not sure what you are trying to do.
Your listener should be the first control in the array (index = 0) and connections should be accepted on one of the controls (index = 1 and up) that is closed.
Take a look at the ConnectionRequest code that I posted earlier today on
http://www.vbforums.com/showthread.p...19#post1979519
-
Apr 13th, 2005, 08:53 PM
#6
Thread Starter
Fanatic Member
Re: First piece of data not sending?
I don't really understand, why does it matter? The servers always connect with the client just fine, and all data sent that wasn't in the listening server's sub send just fine. Either way, I suppose I'll try it...
-
Apr 13th, 2005, 09:11 PM
#7
Thread Starter
Fanatic Member
Re: First piece of data not sending?
Found the problem, apparently closing and listening the listener socket was screwing with something, anyone know why this is?
Here's the revised code:
VB Code:
Private Sub sckSendConnection_ConnectionRequest(ByVal requestID As Long)
Dim I As Integer
For I = 0 To sckConnections.UBound - 1
If sckConnections(I).State = sckListening Or sckConnections(I).State = sckClosing Then
sckConnections(I).Close
sckConnections(I).Accept requestID
sckConnections(I).SendData "PORT" & Chr(1) & CStr(I) & Splitter
Exit Sub
End If
Next I
'load a new one
Load sckConnections(sckConnections.UBound + 1)
'and set I to ubound -1
I = sckConnections.UBound - 1
sckConnections(I + 1).LocalPort = sckConnections(I).LocalPort + 1
sckConnections(I + 1).Listen
'connect
sckConnections(I).Close
sckConnections(I).Accept requestID
sckConnections(I).SendData "PORT" & Chr(1) & CStr(I) & Splitter
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
|