Oppure

Loading
30/11/08 6:45
GoLDBeRG
salve ragazzi.. dovrei fare una dll in vb6 con i winsock per poterli usare su .net.

questo è il codice della DLL

Private frm As Form1
Public WithEvents wsk1 As Winsock
Public port As Integer

Private Sub Class_Initialize()
Set frm = New Form1
   Load frm
Set wsk1 = frm.Winsock1
End Sub

Public Sub ascolta()
  wsk1.LocalPort = port
  wsk1.Listen
End Sub

Private Sub wsk1_ConnectionRequest(ByVal requestID As Long)
wsk1.Accept (requestID)
End Sub


e questo il codice per il .NET

 Public Shared Sub ascoltoporta(ByVal port As Integer)
        Try
            Dim c As New Progetto1.Class1
            c.port = port
            c.ascolta()
        Catch
        End Try
    End Sub


solo che è come se le porte nn si aprissero....nn da nessun errore ma le porte restano chiuse...io non riesco a capire... voi?
aaa
30/11/08 16:00
Gianluca87
Ciao, perchè non usi la classe Socket di .net?
funziona meglio...e non hai bisogno di importare oggetti da vb che non è il massimo...
aaa
30/11/08 22:06
GoLDBeRG
invece di usare il vb6 mi hanno consigliato... se davvero voglio che questo server dc++ possa reggere 10.000 client, di usare le api native del winsock che ha gia windows...

Imports System.Text
Imports System.Collections
Imports System.Runtime.InteropServices

Public Class CONN

    'porta di ascolto
    Public port As Integer

    'dichiarazioni per il socket
    Public Const SUCCESS As Integer = 0
    Public Const HIGH_VERSION As Integer = 2
    Public Const LOW_VERSION As Integer = 2
    Public Const WORD_VERSION As Short = 36

    'struttura socket 
    Public Structure WSAData
        Public wVersion As Short
        Public wHighVersion As Short
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=257)> Public Description As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=129)> Public Status As String
        Public MaxSockets As Integer
        Public MaxUdpDg As Integer
        Public vendorInfoPointer As IntPtr
    End Structure

    'struttura address socket
    Public Structure sockaddr
        Dim sa_family As Integer
        Dim sa_data() As Char
    End Structure

    'struttura address socket IPV4
    Public Structure sockaddr_in
        Dim sin_family As Integer
        Dim sin_port As Integer
        Dim in_addr As sockaddr
        Dim sin_zero() As Char
    End Structure

    'dichiarazione della chiamate alle funzioni che dovro' affettuare
    Declare Function WSAStartup Lib "ws2_32.dll" (ByVal versionRequested As Int16, ByVal infoBuffer As WSAData) As Integer
    Declare Function WSACleanup Lib "ws2_32.dll" () As Int32
    Declare Function accept Lib "ws2_32.dll" (ByVal socketHandle As IntPtr, ByRef socketAddress As sockaddr, ByRef addressLength As Integer) As IntPtr
    Declare Function bind Lib "ws2_32.dll" (ByVal socketHandle As IntPtr, ByRef socketAddress As sockaddr_in, ByVal addressLength As Integer) As Integer


    Public Sub parti()
        'viene eseguita per prima questa procedura
        Dim resultCode As Integer = 0
        Dim data As WSAData

        data = New WSAData
        data.wHighVersion = HIGH_VERSION
        data.wVersion = LOW_VERSION

        resultCode = WSAStartup(WORD_VERSION, data)
        If (resultCode = SUCCESS) Then
            WSACleanup()
        End If

        'ho inizializzato il motore delle winsocket per modo di dire 
        'adesso qui dovrei chiamare la procedura socket che mi restituisce il socket...poi
        'metterlo in ascolto e bla bla bla....

    End Sub


pero' non so continuare.... chi è disposto a darmi una mano?
aaa
01/12/08 10:26
Gianluca87
usare le api di win da c++ è una soluzione....
non è la strada + facile ma sicuramente la + efficiente in termini di performance / utilizzo risorse
aaa
01/12/08 10:28
Gianluca87
parlando con HeDo effettivamente mi ha suggerito che la maniera migliore per fare una cosa del genere è gestirti le connessioni con una libreria fatta in c++ che usa direttamente le api di winzoz
aaa