elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  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 2,787 veces)
CH4ØZ

Desconectado Desconectado

Mensajes: 108



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

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
  1. Public Class Connection
  2.  
  3.    Public Class Client
  4.        Private _Server As String
  5.        Private _Port As Integer
  6.        Private c_Socket As New TcpClient
  7.        Private c_Stream As NetworkStream
  8.  
  9. #Region "Props"
  10.  
  11.        Public Property Server() As String
  12.            Get
  13.                Server = _Server
  14.            End Get
  15.            Set(ByVal value As String)
  16.                _Server = value
  17.            End Set
  18.        End Property
  19.  
  20.        Public Property Port() As Integer
  21.            Get
  22.                Port = _Port
  23.            End Get
  24.            Set(ByVal value As Integer)
  25.                _Port = value
  26.            End Set
  27.        End Property
  28.  
  29. #End Region
  30.  
  31. #Region "Eventos"
  32.  
  33. #Region "Declaracion(delegados)"
  34.  
  35.        Public Delegate Sub _OnConnect(ByVal server As String, ByVal port As Integer)
  36.        Public Delegate Sub _OnDisconect()
  37.        Public Delegate Sub _OnError(ByVal Info As String)
  38.        Public Delegate Sub _OnSendComplete()
  39.  
  40. #End Region
  41.  
  42. #Region "Declaracion(Evento)"
  43.  
  44.        Public Event OnConnect As _OnConnect
  45.        Public Event OnDisconnect As _OnDisconect
  46.        Public Event OnError As _OnError
  47.        Public Event OnSendComplete As _OnSendComplete
  48.  
  49. #End Region
  50.  
  51. #End Region
  52.  
  53. #Region "Funciones"
  54.  
  55.        Public Sub Connect(ByVal server As String, ByVal port As Integer)
  56.            _Server = server
  57.            _Port = port
  58.            Connect()
  59.        End Sub
  60.  
  61.        Public Sub Connect()
  62.            Try
  63.                c_Socket.Connect(_Server, _Port)
  64.                c_Stream = c_Socket.GetStream()
  65.                RaiseEvent OnConnect(_Server, _Port)
  66.            Catch ex As Exception
  67.                RaiseEvent OnError(ex.Message)
  68.            End Try
  69.        End Sub
  70.  
  71.        Public Sub Disconnect()
  72.            Try
  73.                c_Socket.Close()
  74.                c_Stream.Close()
  75.                RaiseEvent OnDisconnect()
  76.            Catch ex As Exception
  77.                RaiseEvent OnError(ex.Message)
  78.            End Try
  79.        End Sub
  80.  
  81.        Public Sub Send(ByVal Data As String)
  82.            Try
  83.                Dim Buffer As Byte()
  84.                Buffer = Encoding.ASCII.GetBytes(Data)
  85.                c_Stream.Write(Buffer, 0, Buffer.Length)
  86.                c_Stream.Flush()
  87.                RaiseEvent OnSendComplete()
  88.            Catch ex As Exception
  89.                RaiseEvent OnError(ex.Message)
  90.            End Try
  91.        End Sub
  92.  
  93. #End Region
  94.  
  95.    End Class
  96.  
  97. End Class

Servidor:
Código
  1. Public Class Connection
  2.  
  3.    Public Class Server
  4.  
  5.        Private _Port As Integer
  6.        Private s_Listener As TcpListener
  7.        Private s_Socket As Socket
  8.        Private s_Timer As New Timers.Timer(50)
  9.        Private b_Listen As Boolean = False
  10.  
  11. #Region "Eventos"
  12.  
  13. #Region "Declaracion(delegados)"
  14.  
  15.        Public Delegate Sub _OnListening(ByVal port As Integer)
  16.        Public Delegate Sub _OnStop()
  17.        Public Delegate Sub _OnAccept(ByVal server As String)
  18.        Public Delegate Sub _RecievedData(ByVal Data As String, ByVal bytes As Integer)
  19.        Public Delegate Sub _OnError(ByVal Info As String)
  20.  
  21. #End Region
  22.  
  23. #Region "Declaracion(Evento)"
  24.  
  25.        Public Event OnStartListening As _OnListening
  26.        Public Event OnStopListening As _OnStop
  27.        Public Event OnConnectionAccept As _OnAccept
  28.        Public Event OnDataRecieved As _RecievedData
  29.        Public Event OnError As _OnError
  30.  
  31. #End Region
  32.  
  33. #End Region
  34.  
  35. #Region "Props"
  36.  
  37.        Public Property Port() As Integer
  38.            Get
  39.                Port = _Port
  40.            End Get
  41.            Set(ByVal value As Integer)
  42.                _Port = value
  43.            End Set
  44.        End Property
  45.  
  46. #End Region
  47.  
  48. #Region "Funciones"
  49.  
  50.        Public Sub StartListen(ByVal port As Integer)
  51.            _Port = port
  52.            StartListen()
  53.        End Sub
  54.  
  55.        Public Sub StartListen()
  56.            Try
  57.                Dim _server As IPAddress = IPAddress.Parse("127.0.0.1")
  58.                s_Listener = New TcpListener(_server, _Port)
  59.                s_Listener.Start()
  60.                b_Listen = True
  61.                AddHandler s_Timer.Elapsed, AddressOf s_Timer_Tick
  62.                RaiseEvent OnStartListening(_Port)
  63.            Catch ex As Exception
  64.                RaiseEvent OnError(ex.Message)
  65.            End Try
  66.        End Sub
  67.  
  68.        Public Sub StopListen()
  69.            Try
  70.                b_Listen = False
  71.                s_Listener.Stop()
  72.                s_Socket.Close()
  73.                RemoveHandler s_Timer.Elapsed, AddressOf s_Timer_Tick
  74.                RaiseEvent OnStopListening()
  75.            Catch ex As Exception
  76.                RaiseEvent OnError(ex.Message)
  77.            End Try
  78.        End Sub
  79.  
  80. #End Region
  81.  
  82. #Region "Internal"
  83.  
  84.        Private Sub s_Timer_Tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
  85.            Dim Data As Byte(), b As Boolean = False
  86.            Data = Nothing
  87.            While b_Listen = True
  88.                s_Socket = s_Listener.AcceptSocket()
  89.                If b = False Then
  90.                    s_Socket.SendTimeout = 100
  91.                    b = True
  92.                End If
  93.                RaiseEvent OnConnectionAccept(s_Socket.RemoteEndPoint.ToString)
  94.                s_Socket.Receive(Data, s_Socket.ReceiveBufferSize, SocketFlags.None)
  95.                RaiseEvent OnDataRecieved(Encoding.ASCII.GetString(Data), Data.Length)
  96.            End While
  97.        End Sub
  98.  
  99. #End Region
  100.  
  101.    End Class
  102.  
  103. End Class


En línea

no me juzguen si no me conocen
CH4ØZ

Desconectado Desconectado

Mensajes: 108



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

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

Edit:
BUMP


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

no me juzguen si no me conocen
CH4ØZ

Desconectado Desconectado

Mensajes: 108



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

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: 59


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


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

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: 108



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

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 Visual Basic
APOKLIPTICO 9 3,166 Último mensaje 6 Octubre 2007, 23:12 pm
por APOKLIPTICO
Problema con sockets
Bases de Datos
XafiloX 1 2,554 Último mensaje 9 Febrero 2010, 00:39 am
por ^Tifa^
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines