Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 21
  1. #1
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303

    [VB6] winsock è multiconnessione

    ciao a tutti.
    Qual' è il modo migliore per far sì che un server accetti più connessioni, al momento il server è così composto

    codice:
    Private Sub Command1_Click()
    Timer1.Interval = 500
    Winsock1.LocalPort = Text2.Text
    Winsock1.Listen
    List2.AddItem "Il server è Online..."
    End Sub
    
    Private Sub Command2_Click()
    Winsock1.Close
    List2.AddItem "Il Server è chiuso.."
    End Sub
    
    Private Sub Command3_Click()
    Winsock1.SendData Text1.Text
    List2.AddItem List2.Text & Text1.Text
    End Sub
    
    
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
     If Winsock1.State <> sckClosed Then Winsock1.Close
     Winsock1.Accept requestID
     
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    
    Dim Password As String
    Password = Text3.Text
    Static Autenticato As Boolean
    Dim Dati As String
    Winsock1.GetData Dati, vbString
    DoEvents
    List2.AddItem List2.Text & "remoto> " & Dati '& vbCrLf  ' Aggiunge il Testo
    
    If Autenticato = False Then
      If Dati = Password Then
        Autenticato = True
        List1.AddItem Winsock1.RemoteHostIP
        List2.AddItem "Welcome.."
        Winsock1.SendData "Welcome " & Winsock1.RemoteHostIP
      Else
        Winsock1.Close
      End If
      
    End If
    
    End Sub

  2. #2
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    preso da msdn
    cosa c' è di sbagliato?

    codice:
    Private intMax As Long
    
    Private Sub Form_Load()
       intMax = 0
       sckServer(0).LocalPort = 1001
       sckServer(0).Listen
    End Sub
    
    Private Sub sckServer_ConnectionRequest _
    (Index As Integer, ByVal requestID As Long)  
       If Index = 0 Then
          intMax = intMax + 1
          Load sckServer(intMax)
          sckServer(intMax).LocalPort = 0
          sckServer(intMax).Accept requestID
          Load txtData(intMax)
       End If
    End Sub
    Perchè mi genera l' errore ??

  3. #3
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    fatto altro giretto, altro codice ma l' errore è sempre lo stesso perchè?

    codice:
    Allow Multiple Winsock Connections to One Server
    The Winsock control allows you to make only one connection between two computers. However, you can create multiple connections (many computers to one) by creating multiple instances of the Winsock control at run time. 
    Add a Winsock control to your form and set its index to 0, then add this code into the server machine to allow multiple connections to it: 
    
     
    Option Explicit
    Public NumSockets As Integer
    '//Public Variable to track number of Connections
    
    Private Sub Form_Load()
    	Caption = Winsock1(0).LocalHostName & _
    		Winsock1(0).LocalIP
    	Winsock1(0).LocalPort = 1066
    	Print "Listening to " + Str(Winsock1(0).LocalPort)
    	Winsock1(0).Listen
    End Sub
    
    Private Sub Winsock1_Close(Index As Integer)
    	Print "Connection Closed :" & _
    		Winsock1(Index).RemoteHostIP
    	Winsock1(Index).Close
    End Sub
    
    Private Sub Winsock1_ConnectionRequest(Index As Integer, _
    	ByVal requestID As Long)
    	Print "Connection Request from : " & _
    		Winsock1(Index).RemoteHostIP
    	NumSockets = NumSockets + 1
    	'//Increase Number of Sockets by one.
    	Load Winsock1(NumSockets)
    	'//Load a New Winsock Object Nusockets as Index Value
    	Winsock1(NumSockets).Accept requestID
    	'//Accept the New Connection
    End Sub
    
    Private Sub Winsock1_DataArrival(Index As Integer, ByVal _
    	bytesTotal As Long)
    	Dim vtData As String
    	Winsock1(Index).GetData vtData, vbString
    	Print vtData
    End Sub
    
    You should now be able to continue to accept connections from multiple sources.

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Hai usato 3 messaggi ... ma l'errore qual e'? E in che riga si manifesta?

  5. #5
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    buongiorno,
    l'errore è quello evidenziato in rosso:

    Private Sub sckServer_ConnectionRequest _
    (Index As Integer, ByVal requestID As Long)

    Errore di compilazione:

    la dichiarazione della routine non corrisponda alla descrizione dell' evento o della routine con lo stesso nome

  6. #6
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Quella dichiarazione presuppone due cose

    1) che il winsock che hai inserito nel form si chiami sckServer

    2) che faccia parte di un array e abbia indice 0

    E' cosi'?

  7. #7
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    si

  8. #8
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    Ne sei sicuro? Hai controllato bene nome e proprieta' Index?

    L'unica spiegazione di quell'errore e' questa ...

  9. #9
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    ma non ci capisco più nulla questo non è altro che un copia è incolla:

    codice:
    Private intMax As Long
    
    Private Sub Form_Load()
       intMax = 0
       sckServer(0).LocalPort = 1001
       sckServer(0).Listen
    End Sub
    
    Private Sub sckServer_ConnectionRequest _
    (Index As Integer, ByVal requestID As Long)  
       If Index = 0 Then
          intMax = intMax + 1
          Load sckServer(intMax)
          sckServer(intMax).LocalPort = 0
          sckServer(intMax).Accept requestID
          Load txtData(intMax)
       End If
    End Sub
    cosa c' è di sbagliato? :master:
    il winsock l' ho chiamato sckServer

  10. #10
    Utente di HTML.it L'avatar di x69asterix
    Registrato dal
    Jan 2005
    Messaggi
    1,303
    chiedo venia!
    la proprità index era vuota

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.