Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - _katze_

#41
interesante,,tengo disponibilidad horario soy de argentina y en lo que guste podemos hacer!
#42
envia el usuario y un daato cm WinsockClient.SendData Usuario & "enter" 'Enter
y lo lees en donde recibe el winsok y lo ejecutas..
#43
leo pruebo y te digo, gracias, la verdad no encontre pero lo mas seguro busque mal.
#44
hola amigos quisiera saber y de que manera podria copiar una matriz de byte en una estructura, intente con marshall pero me da error, y se que rtlmovememory podria pero quisiera ver algo que sea nativo.gracias
#45
espacio de nombres ! "Drawing.Image" de hay lee algo por la red y problema resuelto en dos lineas
#46
busca expresiones regulares para validar mail! pero igual esta bueno! y no lo probe
#47
Hola a todos amigos ! les cuento e creado esa clase (son dos), para el uso de socket, pero tengo un problema cuando voy a hacer uso de los eventos ! al mostrarlos me aparecen como privados y me da error en listview y demas cosas, que podra ser ? o estoy haciendo algo mal?

Código (vbnet) [Seleccionar]
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Namespace Network
    Public Class Cliente
        Implements IDisposable
#Region " Declaraciones "
        Private Socket As Socket
        Private CallBackHandler As AsyncCallback
        Private ClientList As ArrayList = ArrayList.Synchronized(New ArrayList())
        Private objEndPoint As IPEndPoint
        Private ID As Integer = 0
        Private BufData As Byte() = New Byte(65536) {}
        Public Event DatosRecibidos(ByVal Datos() As Byte, ByVal SocketID As Integer)
        Public Event ErrorCatched(ByVal msg As String)
        Public Event Desconectado()
        Public Event Conectado(ByVal SocketID As Integer)
#End Region

#Region " Procedimientos "
        Public Sub Conectar(ByVal vsIp As String, ByVal viPuerto As Integer)
            Try
                If Socket IsNot Nothing Then
                    If Socket.Connected Then
                        Call Desconectar()
                    End If
                End If
                Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                Socket.NoDelay = True
                Socket.DontFragment = False
                Socket.LingerState.Enabled = True
                Socket.LingerState.LingerTime = 100
                Socket.SendBufferSize = 65536
                Socket.ReceiveBufferSize = 65536
                Dim endpoint As Net.IPEndPoint
                endpoint = New IPEndPoint(IPAddress.Parse(vsIp), viPuerto)
                Socket.Connect(endpoint)

                If Socket.Connected Then
                    objEndPoint = CType(Socket.RemoteEndPoint, IPEndPoint)
                    Call EsperaDeDatos()
                End If
            Catch ex As SocketException
                RaiseEvent ErrorCatched(ex.Message)
            End Try
        End Sub
        Public Sub Desconectar()
            Try
                If Socket IsNot Nothing Then
                    If Socket.Connected Then
                        Socket.Disconnect(True)
                    End If
                    Socket.Close()
                    Socket = Nothing
                End If
                RaiseEvent Desconectado()
            Catch SE As SocketException
                RaiseEvent ErrorCatched(SE.Message)
            End Try
        End Sub
        Public Sub Desconectar(ByVal SocketID As Integer)
            DropClient(GetSocketPacket(SocketID), False, False)
        End Sub
        Public Function EnviarMensaje(ByVal SocketID As Integer, ByVal Datos() As Byte) As Boolean

            Try
                If GetSocketPacket(SocketID).mClientSocket.Connected Then
                    GetSocketPacket(SocketID).mClientSocket.Send(Datos)
                    Return (True)
                Else
                    Return (False)
                End If
            Catch
                Return (False)
            End Try
        End Function

        Public Function EnviarMensaje(ByVal SocketID As Integer, ByVal Mensaje As String) As Boolean
            Try
                If GetSocketPacket(SocketID).mClientSocket.Connected Then
                    Dim NetStream As New NetworkStream(GetSocketPacket(SocketID).mClientSocket)

                    Dim SocketStream As New StreamWriter(NetStream)
                    SocketStream.Write(Mensaje)

                    SocketStream.Flush()
                    Return (True)
                Else
                    Return (False)
                End If
            Catch
                Return (False)
            End Try
        End Function


#End Region

#Region " Procedimientos Privados "
        Private Sub EsperaDeDatos()
            Try
                If CallBackHandler Is Nothing Then
                    CallBackHandler = New AsyncCallback(AddressOf OnDataReceived)
                End If
                Dim socketId As Integer = 1
                If ClientList.Count > 0 Then
                    socketId = TryCast(ClientList(ClientList.Count - 1), SocketPacket).mSocketID + 1
                End If
                Dim ConnectedClient As New SocketPacket(Socket, socketId)
                ClientList.Add(ConnectedClient)
                ID += 1
                Socket.BeginReceive(BufData, 0, BufData.Length, SocketFlags.None, CallBackHandler, Socket)
                RaiseEvent Conectado(ConnectedClient.mSocketID)
            Catch SE As SocketException
                RaiseEvent ErrorCatched(SE.Message)
            Catch E As Exception
                RaiseEvent ErrorCatched(E.Message)
            End Try
        End Sub
        Private Sub OnDataReceived(ByVal Asyn As IAsyncResult)
            Try
                Dim ConnectedClient As SocketPacket = DirectCast(Asyn.AsyncState, SocketPacket)
                If Not ConnectedClient.mClientSocket.Connected Then
                    Return
                End If
                Dim CollectedDataLength As Integer = Socket.EndReceive(Asyn)
                If CollectedDataLength = 0 Then
                    If ConnectedClient.mClientSocket.Connected Then
                        ConnectedClient.mClientSocket.Disconnect(False)
                    End If
                    ConnectedClient.mClientSocket.Close()

                    RaiseEvent Desconectado()
                Else
                    RaiseEvent DatosRecibidos(BufData, ConnectedClient.mSocketID)
                    EsperaDeDatos()
                End If
            Catch generatedExceptionName As ObjectDisposedException
                RaiseEvent Desconectado()
            Catch SE As SocketException
                If SE.ErrorCode = 10054 Then
                    RaiseEvent Desconectado()
                Else
                    RaiseEvent ErrorCatched(SE.Message)
                End If
            Catch E As Exception
                RaiseEvent ErrorCatched(E.Message)
            End Try
        End Sub
        Private Sub DropClient(ByVal DisposedSocket As SocketPacket, ByVal DisconnectedRemotly As Boolean, ByVal DisconnectedForcibly As Boolean) 'tirar clientes
            Try

                DisposedSocket.mClientSocket.Shutdown(SocketShutdown.Both)
            Catch
            End Try


            Dim IsRemoved As Boolean = False


            SyncLock ClientList.SyncRoot
                Try

                    Dim SckID As Integer = 0
                    While Not IsRemoved AndAlso (SckID < ClientList.Count)

                        Dim ClientSocket As SocketPacket = DirectCast(ClientList(SckID), SocketPacket)


                        If ClientSocket.mClientSocket Is DisposedSocket.mClientSocket Then

                            ClientList.Remove(ClientSocket)

                            ID -= 1

                            IsRemoved = True

                            RaiseEvent Desconectado()
                        End If
                        SckID += 1
                    End While
                Catch E As Exception
                    RaiseEvent ErrorCatched(E.Message)
                End Try
            End SyncLock
        End Sub
        Private Function GetSocketPacket(ByVal SocketID As Integer) As SocketPacket ' obtener paquetes del socket

            Dim mClientSocket As SocketPacket = Nothing

            For Each ClientSocket As SocketPacket In ClientList

                If ClientSocket.mSocketID = SocketID Then

                    mClientSocket = ClientSocket

                    Exit For
                End If
            Next
            Return (mClientSocket)
        End Function

#End Region

#Region "propiedades"
        Public ReadOnly Property IsConectado() As Boolean
            Get
                Return Socket.Connected
            End Get
        End Property

        Public ReadOnly Property RemoteEndPoint() As System.Net.IPEndPoint
            Get
                Return objEndPoint
            End Get
        End Property
        Public ReadOnly Property TotalConectado As Integer
            Get
                Return ID
            End Get
        End Property
#End Region

#Region "Rem -> [ Socket Packet Helper Class ]"
        Class SocketPacket
            Friend ReadOnly mClientSocket As Socket
            Friend ReadOnly mSocketID As Integer

            Public Sub New(ByVal ClientSocket As Socket, ByVal SocketID As Integer)
                mClientSocket = ClientSocket
                mSocketID = SocketID
            End Sub
        End Class
#End Region

#Region " IDisposable Support "

        Private disposedValue As Boolean = False        ' Para detectar llamadas redundantes

        ' IDisposable
        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
            If Not Me.disposedValue Then
                If disposing Then
                    ' TODO: Liberar otro estado (objetos administrados).
                End If

                ' TODO: Liberar su propio estado (objetos no administrados).
                ' TODO: Establecer campos grandes como Null.
            End If
            Me.disposedValue = True
        End Sub
        ' Visual Basic agregó este código para implementar correctamente el modelo descartable.
        Public Sub Dispose() Implements IDisposable.Dispose
            ' No cambie este código. Coloque el código de limpieza en Dispose (ByVal que se dispone como Boolean).
            Dispose(True)
            GC.SuppressFinalize(Me)
        End Sub
#End Region

    End Class
End Namespace
#48
la respuesta de novlucker es buena! sino puedes cambiar por hacerlo con WebClient y  de manera asincronica, asi no se te frisara el form ni nada y tiene varios eventos los cuales puedes usar para obtener la descarga y para el porcentaje! suerte
#49
.NET (C#, VB.NET, ASP) / Re: Envio emails vb.net
18 Agosto 2011, 00:24 AM
Código (vbnet) [Seleccionar]
Environment.NewLineese es la correcta. saludos y proba con eso !
#50
Código (vbnet) [Seleccionar]
''' <summary>
   ''' para enviar mail con el servidor de hotmail
   ''' </summary>
   ''' <param name="mail">Mail del Remitente</param>
   ''' <param name="contraseña">Contraseña Del Remitente</param>
   ''' <param name="asunto">Asunto Del Mail</param>
   ''' <param name="destinatario">Mail para quien va dirigido el mail</param>
   ''' <param name="cuerpo">Cuerpo Del Mensaje</param>
   ''' <param name="File">Archivo para Enviar Adjunto al Mail</param>
   ''' <param name="smtp">Para Editar el Servidor Smtp</param>
   ''' <param name="puerto">Puerto Del Servidor Smtp es Opcional si el servidor lo requiere</param>
   ''' <remarks></remarks>
   Private Sub EnviarMail(ByVal mail As String, ByVal contraseña As String, ByVal asunto As String, ByVal destinatario As String, ByVal cuerpo As String, Optional ByVal File As String = Nothing, Optional ByVal smtp As String = "smtp.live.com", Optional ByVal puerto As Integer = 587)


       Dim servidor As New System.Net.Mail.SmtpClient

       Dim mails As New System.Net.Mail.MailMessage

       Try
           If System.IO.Path.IsPathRooted(File) Then
               Dim FileAdjunto As New Net.Mail.Attachment(File)
               mails.Attachments.Add(FileAdjunto)
           End If
           With mails
               .From = New System.Net.Mail.MailAddress(mail, mail, System.Text.Encoding.UTF8)
               .Subject = asunto
               .SubjectEncoding = System.Text.Encoding.UTF8
               .To.Add(destinatario)
               .Body = cuerpo
               .BodyEncoding = System.Text.Encoding.UTF8
               .IsBodyHtml = False
           End With
           With servidor
               .Host = smtp
               .Port = puerto
               .EnableSsl = True
               .Credentials = New System.Net.NetworkCredential(mail, contraseña)
               .Send(mails)

           End With
       Catch ex As System.Net.Mail.SmtpException
           MessageBox.Show(ex.ToString, "Envio De Mail", MessageBoxButtons.OK, MessageBoxIcon.Error)

       End Try
   End Sub


este es mi code lo que le falta seria que envie un tamaño de archivo especifico...

".IsBodyHtml = False" esta parte lo que hace es que se pueda incluir codigo html dentro del msj pues si haces un html estandar y le agregas todo lo que quieres puedes hacerlo...pues supongo que es lo que necesitas...pon isbodyhtml en true y agrega tu code en html con tamaño tipo y todo lo que quieras darle de formato al correo