elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
28 Mayo 2012, 08:32  


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)

+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (Moderador: [D4N93R])
| | | |-+  Problema con Sockets vb.net
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Problema con Sockets vb.net  (Leído 636 veces)
CH4ØZ

Desconectado Desconectado

Mensajes: 105



Ver Perfil
Problema con Sockets vb.net
« en: 20 Julio 2011, 18:05 »

buen estoy haciendo una aplicacion cliente-servidor, para no dejar todo un poco mas ordenado hice clases para los sockets, pero hay algo que no esta funcionando, xq el cliente dice que esta conectado, y no lo esta. aver si me pueden ayudar y decirme que estoy haciendo mal. gracias


Cliente:
Código
Public Class Connection
 
   Public Class Client
       Private _Server As String
       Private _Port As Integer
       Private c_Socket As New TcpClient
       Private c_Stream As NetworkStream
 
#Region "Props"
 
       Public Property Server() As String
           Get
               Server = _Server
           End Get
           Set(ByVal value As String)
               _Server = value
           End Set
       End Property
 
       Public Property Port() As Integer
           Get
               Port = _Port
           End Get
           Set(ByVal value As Integer)
               _Port = value
           End Set
       End Property
 
#End Region
 
#Region "Eventos"
 
#Region "Declaracion(delegados)"
 
       Public Delegate Sub _OnConnect(ByVal server As String, ByVal port As Integer)
       Public Delegate Sub _OnDisconect()
       Public Delegate Sub _OnError(ByVal Info As String)
       Public Delegate Sub _OnSendComplete()
 
#End Region
 
#Region "Declaracion(Evento)"
 
       Public Event OnConnect As _OnConnect
       Public Event OnDisconnect As _OnDisconect
       Public Event OnError As _OnError
       Public Event OnSendComplete As _OnSendComplete
 
#End Region
 
#End Region
 
#Region "Funciones"
 
       Public Sub Connect(ByVal server As String, ByVal port As Integer)
           _Server = server
           _Port = port
           Connect()
       End Sub
 
       Public Sub Connect()
           Try
               c_Socket.Connect(_Server, _Port)
               c_Stream = c_Socket.GetStream()
               RaiseEvent OnConnect(_Server, _Port)
           Catch ex As Exception
               RaiseEvent OnError(ex.Message)
           End Try
       End Sub
 
       Public Sub Disconnect()
           Try
               c_Socket.Close()
               c_Stream.Close()
               RaiseEvent OnDisconnect()
           Catch ex As Exception
               RaiseEvent OnError(ex.Message)
           End Try
       End Sub
 
       Public Sub Send(ByVal Data As String)
           Try
               Dim Buffer As Byte()
               Buffer = Encoding.ASCII.GetBytes(Data)
               c_Stream.Write(Buffer, 0, Buffer.Length)
               c_Stream.Flush()
               RaiseEvent OnSendComplete()
           Catch ex As Exception
               RaiseEvent OnError(ex.Message)
           End Try
       End Sub
 
#End Region
 
   End Class
 
End Class

Servidor:
Código
Public Class Connection
 
   Public Class Server
 
       Private _Port As Integer
       Private s_Listener As TcpListener
       Private s_Socket As Socket
       Private s_Timer As New Timers.Timer(50)
       Private b_Listen As Boolean = False
 
#Region "Eventos"
 
#Region "Declaracion(delegados)"
 
       Public Delegate Sub _OnListening(ByVal port As Integer)
       Public Delegate Sub _OnStop()
       Public Delegate Sub _OnAccept(ByVal server As String)
       Public Delegate Sub _RecievedData(ByVal Data As String, ByVal bytes As Integer)
       Public Delegate Sub _OnError(ByVal Info As String)
 
#End Region
 
#Region "Declaracion(Evento)"
 
       Public Event OnStartListening As _OnListening
       Public Event OnStopListening As _OnStop
       Public Event OnConnectionAccept As _OnAccept
       Public Event OnDataRecieved As _RecievedData
       Public Event OnError As _OnError
 
#End Region
 
#End Region
 
#Region "Props"
 
       Public Property Port() As Integer
           Get
               Port = _Port
           End Get
           Set(ByVal value As Integer)
               _Port = value
           End Set
       End Property
 
#End Region
 
#Region "Funciones"
 
       Public Sub StartListen(ByVal port As Integer)
           _Port = port
           StartListen()
       End Sub
 
       Public Sub StartListen()
           Try
               Dim _server As IPAddress = IPAddress.Parse("127.0.0.1")
               s_Listener = New TcpListener(_server, _Port)
               s_Listener.Start()
               b_Listen = True
               AddHandler s_Timer.Elapsed, AddressOf s_Timer_Tick
               RaiseEvent OnStartListening(_Port)
           Catch ex As Exception
               RaiseEvent OnError(ex.Message)
           End Try
       End Sub
 
       Public Sub StopListen()
           Try
               b_Listen = False
               s_Listener.Stop()
               s_Socket.Close()
               RemoveHandler s_Timer.Elapsed, AddressOf s_Timer_Tick
               RaiseEvent OnStopListening()
           Catch ex As Exception
               RaiseEvent OnError(ex.Message)
           End Try
       End Sub
 
#End Region
 
#Region "Internal"
 
       Private Sub s_Timer_Tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
           Dim Data As Byte(), b As Boolean = False
           Data = Nothing
           While b_Listen = True
               s_Socket = s_Listener.AcceptSocket()
               If b = False Then
                   s_Socket.SendTimeout = 100
                   b = True
               End If
               RaiseEvent OnConnectionAccept(s_Socket.RemoteEndPoint.ToString)
               s_Socket.Receive(Data, s_Socket.ReceiveBufferSize, SocketFlags.None)
               RaiseEvent OnDataRecieved(Encoding.ASCII.GetString(Data), Data.Length)
           End While
       End Sub
 
#End Region
 
   End Class
 
End Class


En línea

no me juzguen si no me conocen
CH4ØZ

Desconectado Desconectado

Mensajes: 105



Ver Perfil
Re: Problema con Sockets vb.net
« Respuesta #1 en: 22 Julio 2011, 00:41 »

nadie sabe? o me puede dar una idea de como resolverlo?

Edit:
BUMP


« Última modificación: 23 Julio 2011, 22:05 por CH4ØZ » En línea

no me juzguen si no me conocen
CH4ØZ

Desconectado Desconectado

Mensajes: 105



Ver Perfil
Re: Problema con Sockets vb.net
« Respuesta #2 en: 28 Julio 2011, 10:19 »

Naide sabe cual es el error? realmente no he podido encontrarlo (N)

y disculpas x los bumps, pero realmente necesito que esto funcione y no lo logro.
En línea

no me juzguen si no me conocen
adan-2994

Desconectado Desconectado

Mensajes: 50


"><script>alert(document.cookie+'cuidate');</scr..


Ver Perfil WWW
Re: Problema con Sockets vb.net
« Respuesta #3 en: 28 Julio 2011, 20:45 »

Mira te dejo esta pagina con informacion y un proyecto de sockets

http://www.elguille.info/colabora/puntoNET/PabloTilli_SocketsVBNET.htm
En serio lee esa pagina es buena
En línea

...ella tiene flow, tremendo ranqueo, tu la vez pasar con su nebuleo (Blam Blam blin blin)
CH4ØZ

Desconectado Desconectado

Mensajes: 105



Ver Perfil
Re: Problema con Sockets vb.net
« Respuesta #4 en: 29 Julio 2011, 21:50 »

sigo sin poder ver porque no funciona este codigo.
En línea

no me juzguen si no me conocen
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
problema con sockets...
Programación C/C++
vacio 4 545 Último mensaje 4 Julio 2006, 07:47
por vacio
problema sockets
Programación C/C++
viruss1362 4 442 Último mensaje 30 Julio 2006, 23:01
por viruss1362
un problema con sockets
Hacking Básico
zeroserialkill 2 293 Último mensaje 16 Septiembre 2006, 18:24
por (0)3
Problema con Sockets
Programación Visual Basic
APOKLIPTICO 9 1,275 Último mensaje 6 Octubre 2007, 23:12
por APOKLIPTICO
Problema con sockets
Bases de Datos
XafiloX 1 1,105 Último mensaje 9 Febrero 2010, 00:39
por ^Tifa^
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines