(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-25-24 09:14 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - VB6 TCP problems New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6337 days
Last view: 6336 days
Posted on 04-13-06 01:41 PM Link | Quote
um... yeah... I'm trying to get a program that acts as a server on a network, using the TCP protocol in VB6. My problem is, the server usually doesn't recieve connection requests after the first one. The way the server program was designed was that there would be 33 MS Winsock controls on the form, which is height 0 and width 0. There would be 32 or them in an array which handle connections, and one which sets them up, taking in connection requests and making an open port accept them. However, after the first connection, the "TCPConnector" winsock control stops recieving requests. Could someone please tell me what I am doing wrong with this code? There is also a timer, but that's used for mostly the caption at the bottom.


Dim openport(31) As Boolean
Dim Marqueescroll As Integer
Dim Marquee As String

Private Sub Form_Load()
Marqueescroll = 0
Me.Height = 0
Me.Width = 0
For a = 0 To 31
openport(a) = True
Next a
TCPConnector.Bind 2000, TCPConnector.LocalIP
TCPConnector.Listen
End Sub

Private Sub TCPClientport_Close(Index As Integer)
openport(Index) = True
Debug.Print "Connection lost"
End Sub

Private Sub TCPClientport_Connect(Index As Integer)
openport(Index) = False
Debug.Print "connection established"
End Sub

Private Sub TCPClientport_ConnectionRequest(Index As Integer, ByVal requestID As Long)
openport(Index) = False
Debug.Print "connection established"
End Sub

Private Sub TCPClientport_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim inarray() As Byte
Dim sendstring As String
TCPClientport(Index).GetData a, vbArray + vbByte, btyestotal
Select Case inarray(0)
Case 3
sendstring = ""
For a = 2 To UBound(inarray)
sendstring = sendstring + Chr$(inarray(a))
Next a
TCPClientport(inarray(1)).SendData Chr$(4) + sendstring
Case Else
sendstring = ""
For a = 0 To UBound(inarray)
sendstring = sendstring + Chr$(inarray(a))
Next a
Call SendToAll(sendstring, Index)
End Select
End Sub

Private Sub TCPConnector_ConnectionRequest(ByVal requestID As Long)
Debug.Print "Connection Request"
If PortAvailable Then
Debug.Print "Port available"
Debug.Print TCPClientport(AvailablePort).State
TCPClientport(AvailablePort).Accept requestID
Debug.Print TCPClientport(AvailablePort).State
openport(AvailablePort) = False

Else
Debug.Print "Port unavailable"
TCPConnector.Accept requestID
TCPConnector.SendData Chr$(&HFF)
a = 0
Do While a = 0
TCPConnect.PeekData a, vbByte, 1
Loop
End If
TCPConnector.Close
TCPConnector.Bind 2000, TCPConnector.LocalIP
TCPConnector.Listen
Debug.Print TCPConnector.State
End Sub

Private Function AvailablePort() As Integer
For a = 0 To 31
If openport(a) = True Then AvailablePort = a: Exit Function
Next a
AvailablePort = 0
End Function

Private Function PortAvailable() As Boolean
For a = 0 To 31
If openport(a) = True Then PortAvailable = True: Exit Function
Next a
PortAvailable = False
End Function

Private Function NumClients()
NumClients = 0
For a = 0 To 31
If openport(a) = False Then NumClients = NumClients + 1
Next a
End Function

Private Sub SendToAll(ToSend As String, skip As Integer)
For a = 0 To 31
If TCPClientport(a).State = sckConnected And a <> skip Then TCPClientport(a).SendData ToSend
Next a
End Sub

Private Sub Timer1_Timer()
Dim Marqueelength As Long
Marquee = ""
For a = 0 To 1
Marquee = Marquee + "GW Server -" + Str(NumClients) + " Clients" + " " + "Server IP: " + TCPConnector.LocalIP + " "
Next a
Marqueescroll = Marqueescroll + 1
Marqueelength = Len(Marquee) / 2
If Marqueescroll = Marqueelength Then Marqueescroll = 1
Me.Caption = Mid(Marquee, Marqueescroll, 22)
If TCPConnector.State <> sckClosed And TCPConnector.State <> sckConnected Then
TCPConnector.Close
TCPConnector.Bind 2000, TCPConnector.LocalIP
TCPConnector.Listen
End If
Debug.Print TCPConnector.State
End Sub


If anyone would like the whole .vbp project and form and everything, I can package the three things into a .zip file and upload for them.

EDIT: nvm. The error was "Address In Use", from the program connecting to the server code above. ...That's on the client side, right?


(edited by Sukasa + on 04-13-06 03:43 PM)
dormento

Red Goomba


 





Since: 11-18-05

Last post: 6489 days
Last view: 6336 days
Posted on 04-13-06 07:02 PM Link | Quote
snip
Edit: Dangit, seems I didn't read your post right

Edit2: Your answer might be here.






(edited by dormento on 04-13-06 06:07 PM)
(edited by dormento on 04-14-06 07:31 PM)
dcahrakos

490


 





Since: 11-17-05

Last post: 6553 days
Last view: 6553 days
Posted on 04-14-06 08:35 PM Link | Quote
If I remember correctly, if you are using winsock, you need to turn the winsock control into an array.

heres a link http://www.winsockvb.com/forums/showthread.php?s=&threadid=3069

however, if you are planning on a lot of connections, and are using the control, consider using the actual API:

http://www.vbip.com/winsock-api/select-socket/select-socket-01.asp
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6337 days
Last view: 6336 days
Posted on 04-24-06 03:43 PM Link | Quote
Eh, I later found the problem. I fixed it, it was client-side. Now, however, there is a new problem. If I have more than one client, then only the last person to join in will recieve messages, the rest can only send, and won't even recieve the messages they sent!
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - VB6 TCP problems |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.011 seconds; used 368.12 kB (max 444.01 kB)