|
-
Mar 14th, 2005, 07:55 PM
#1
Thread Starter
Junior Member
Re: Socket problem
Server Code for Server: (Port 999)
Code:
Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
'Declares Memory Variables
Dim lngA As Long
Dim strRemoteIP As String
'Sets Variables
strRemoteIP = Socket(Index).RemoteHostIP
'Checks If IP's banned
If IsBanned(strRemoteIP) = True Then Exit Sub
'Loops through each Socket
For lngA = 1 To Socket.UBound
'Checks for Free Socket
If Socket(lngA).State <> 7 Then
'Closes Socket
Socket(lngA).Close
Socket(lngA).Accept requestID
'Removes All Data from SubSocket
Call DumpSubSocket(Index)
'Ends Execution
Exit Sub
End If
Next lngA
'Finds Upper Bound of Socket plus one
lngA = Socket.UBound + 1
'Removes All Data from SubSocket
ReDim SubSocket(lngA)
Call DumpSubSocket(CInt(lngA))
'Loads New Socket
Load Socket(lngA)
Socket(lngA).Close
Socket(lngA).Accept requestID
End Sub
And the client part is pretty streight forward.
Code:
'Attempts to Connect to Central Data Server
frmMain.SocketT2A.Close
frmMain.SocketT2A.Connect "127.0.0.1", 999
Again, it connects fine. Then I close the application (in VB IDE) and relaunch it b/c I changed something and it doesnt work. Then, if I give it a few minutes and run the exact same code it does work. Kind of odd to me. As for the programming, I do know what I'm doing so that shouldnt be a problem.
Also on the server side; it doesnt banned anyone yet. So that shouldnt effect anything. I would release all the code but I cant
-
Mar 14th, 2005, 08:16 PM
#2
Frenzied Member
Re: Socket problem
 Originally Posted by Carsten
Again, it connects fine. Then I close the application (in VB IDE) and relaunch it b/c I changed something and it doesnt work. Then, if I give it a few minutes and run the exact same code it does work. Kind of odd to me. As for the programming, I do know what I'm doing so that shouldnt be a problem.
Also on the server side; it doesnt banned anyone yet. So that shouldnt effect anything. I would release all the code but I cant 
You are setting the port (999) rather than allowing the system to select one that isn't busy. The port will remain in the TIME_WAIT state for about 4 minutes after the connection is closed. This is why I asked you if you were setting the port to some value in my earlier post. You assured us that you had "done many server/client applications and never had problems". I didn't persue the issue.
Set the port to zero before connecting and let the system decide which one to use.
-
Mar 14th, 2005, 10:04 PM
#3
Thread Starter
Junior Member
Re: Socket problem
I dont understand here.
On the server I have to tell it what PORT to listen too, it has to be. And the on the client when I connect, I have to know what port to connect to otherwise it will attempt to connect to a port that isnt open or in use from another application.
So yeah, I either miss understood you or we arent on the same page b/c what you are sayin I have NEVER heard of before. And I do assured you that "I've done many server/client applications and never had problems". Please correct me if I'm wrong .
BTW: If I let the "system" decide what port to use, how would the clients know what port to connect if its diffrent all the time?
Carsten
-
Mar 14th, 2005, 11:01 PM
#4
Frenzied Member
Re: Socket problem
Sorry, I'm having a bad day. Somehow I misread your code.
You have to set the client's RemotePort to the port number that the server is listening on - I assume that it is 999. Set the client's LocalPort to zero and the system will select an unused port number for you.
-
Mar 14th, 2005, 11:16 PM
#5
Member
Re: Socket problem
I haven't coded sockets in vb in a while but doesnt the remotehostip property get filled out after the host accepts the connection?
Kiss, Aerosmith, Black Sabbath, Nazareth, Judas Priest, Status Quo, Cinderella, Scorpions, Tool, SteppenWolf.
-
Mar 15th, 2005, 03:11 AM
#6
KING BODWAD XXI
Re: Socket problem
Try this it might not work but its worth a try
VB Code:
Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
'Declares Memory Variables
Dim lngA As Long
Dim strRemoteIP As String
'Sets Variables
strRemoteIP = Socket(Index).RemoteHostIP
'Checks If IP's banned
If IsBanned(strRemoteIP) = True Then Exit Sub
'Loops through each Socket
For lngA = 1 To Socket.UBound
'Checks for Free Socket
If Socket(lngA).State <> 7 Then
'Closes Socket
Socket(lngA).Close
Socket(lngA).localport = 0
Socket(lngA).Accept requestID
'Removes All Data from SubSocket
Call DumpSubSocket(Index)
'Ends Execution
Exit Sub
End If
Next lngA
'Finds Upper Bound of Socket plus one
lngA = Socket.UBound + 1
'Removes All Data from SubSocket
ReDim SubSocket(lngA)
Call DumpSubSocket(CInt(lngA))
'Loads New Socket
Load Socket(lngA)
Socket(lngA).Close
Socket(lngA).localport = 0
Socket(lngA).Accept requestID
End Sub
VB Code:
'Attempts to Connect to Central Data Server
frmMain.SocketT2A.Close
frmMain.SocketT2A.localport = 0
frmMain.SocketT2A.Connect "127.0.0.1", 999
-
Mar 15th, 2005, 06:52 PM
#7
Thread Starter
Junior Member
Re: Socket problem
@BodwadUK
Tried it, didnt help anything. Anyone else got any other suggestions?
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
|