Results 1 to 19 of 19

Thread: Socket problem

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    South Carolina
    Posts
    31

    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

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Socket problem

    Quote 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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    South Carolina
    Posts
    31

    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

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    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.

  5. #5
    Member
    Join Date
    Feb 2005
    Location
    Usa Nyc
    Posts
    45

    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.

  6. #6
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: Socket problem

    Try this it might not work but its worth a try

    VB Code:
    1. Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2.  
    3.     'Declares Memory Variables
    4.     Dim lngA As Long
    5.     Dim strRemoteIP As String
    6.  
    7.     'Sets Variables
    8.     strRemoteIP = Socket(Index).RemoteHostIP
    9.    
    10.     'Checks If IP's banned
    11.     If IsBanned(strRemoteIP) = True Then Exit Sub
    12.    
    13.     'Loops through each Socket
    14.     For lngA = 1 To Socket.UBound
    15.    
    16.         'Checks for Free Socket
    17.         If Socket(lngA).State <> 7 Then
    18.        
    19.             'Closes Socket
    20.             Socket(lngA).Close
    21.             Socket(lngA).localport = 0
    22.             Socket(lngA).Accept requestID
    23.            
    24.             'Removes All Data from SubSocket
    25.             Call DumpSubSocket(Index)
    26.            
    27.             'Ends Execution
    28.             Exit Sub
    29.            
    30.         End If
    31.     Next lngA
    32.    
    33.     'Finds Upper Bound of Socket plus one
    34.     lngA = Socket.UBound + 1
    35.    
    36.     'Removes All Data from SubSocket
    37.     ReDim SubSocket(lngA)
    38.     Call DumpSubSocket(CInt(lngA))
    39.    
    40.     'Loads New Socket
    41.     Load Socket(lngA)
    42.     Socket(lngA).Close
    43.     Socket(lngA).localport = 0
    44.     Socket(lngA).Accept requestID
    45.    
    46. End Sub

    VB Code:
    1. 'Attempts to Connect to Central Data Server
    2.         frmMain.SocketT2A.Close
    3.         frmMain.SocketT2A.localport = 0
    4.         frmMain.SocketT2A.Connect "127.0.0.1", 999
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2003
    Location
    South Carolina
    Posts
    31

    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
  •  



Click Here to Expand Forum to Full Width