elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
20 Noviembre 2008, 19:34  



+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (Moderadores: BADBYTE-K, hadess_inf)
| | | |-+  VB.NET sockets cliente-servidor
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Imprimir
Autor Tema: VB.NET sockets cliente-servidor  (Leído 443 veces)
Blizknight

Desconectado Desconectado

Mensajes: 7


Ver Perfil
VB.NET sockets cliente-servidor
« en: 08 Marzo 2008, 13:29 »

Hola a todos
estuve haciendo un chat cliente servidor y bueno me base en un codigo base
y estuve probando, cuando termine al probarlo con un amigo no me funcionaba
el puerto que tuiliza es el 6112 y se encontraba abierto
y ademas no tenia firewall. me funciona perfectamente en localhost mas no en inernet.
alguien si me puede ayudar se lo agradeceria aca dejo el codigo del cliente y el cliente y servidor compilado.

saludos

--CLIENTE Y SERVIDOR
Código:
:http://rapidshare.de/files/38762592/Escritorio.rar.html

--CODIGO DEL CLIENTE
Código:
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
    Dim client As TcpClient
    Dim data() As Byte

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
        If txtserver.Text = "" Or txtport.Text = "" Or txtnick.Text = "" Then
            MsgBox("Ingrese Datos para la Conexion")
            Exit Sub
        End If

        If btnstart.Text.Trim = "START" Then
            MsgBox("in")
            Try
                '---connect to server
                client = New TcpClient
                client.Connect(txtserver.Text.Trim, txtport.Text.Trim)
                ReDim data(client.ReceiveBufferSize)
                SendMessage(txtnick.Text)
                '---read from server
                client.GetStream.BeginRead( _
                   data, 0, CInt(client.ReceiveBufferSize), _
                   AddressOf ReceiveMessage, Nothing)
                btnstart.Text = "OUT"
                btnsend.Enabled = True
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        Else
            'DESCONECTA
            Disconnect()
            btnstart.Text = "START"
            btnsend.Enabled = False
        End If


    End Sub

    Private Sub btnsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsend.Click
        SendMessage(txtmsg.Text.Trim)
        txtmsg.Clear()
    End Sub

    Public Sub Disconnect()
        '---DESCONECTA
        Try
            client.GetStream.Close()
            client.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub ReceiveMessage(ByVal ar As IAsyncResult)
        Try
            Dim bytesRead As Integer
            bytesRead = client.GetStream.EndRead(ar)
            If bytesRead < 1 Then
                Exit Sub
            Else
                Dim para() As Object = {System.Text.Encoding.ASCII.GetString(data, 0, bytesRead)}
                Me.Invoke(New delUpdateH(AddressOf Me.UpdateH), para)
            End If
            client.GetStream.BeginRead( _
               data, 0, CInt(client.ReceiveBufferSize), AddressOf ReceiveMessage, Nothing)
        Catch ex As Exception
        End Try
    End Sub

    Public Delegate Sub delUpdateH(ByVal str As String)
    Public Sub UpdateH(ByVal str As String)
        rtxt.AppendText(str)
        txtmain.AppendText(str)
    End Sub

    Public Sub SendMessage(ByVal message As String)
        Try
            '---send a message to the server
            Dim ns As NetworkStream = client.GetStream
            Dim data As Byte() = System.Text.Encoding.ASCII.GetBytes(message)
            '---send the text---
            ns.Write(data, 0, data.Length)
            ns.Flush()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

End Class
En línea
UKWN

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: VB.NET sockets cliente-servidor
« Respuesta #1 en: 11 Marzo 2008, 03:12 »

mmm si tienes modem no se supone que debes de redireccionar el puerto? porque si en localhost (127.0.0.1) te funciona perfectamente entonces debe de ser por tu modem.

Dato Curioso :P: El puerto 6112 es utilizado actualmente por battle.net, los servidores que son host de Starcraft, Warcraft, Diablo II, etc :P.
En línea
elmaro

Desconectado Desconectado

Mensajes: 214


Unas simples palabras...


Ver Perfil WWW
Re: VB.NET sockets cliente-servidor
« Respuesta #2 en: 11 Marzo 2008, 04:53 »

 :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh:
En línea
Páginas: [1] Ir Arriba Imprimir 
Ir a:  







Consolas     La Web de Goku     MilW0rm     MundoDivx

Hispabyte     Truzone     TodoReviews     ZonaPhotoshop

Foros de ayuda    Yashira.org    Videojuegos    indetectables.net   

Noticias Informatica    Seguridad Informática    ADSL    eNYe Sec

Todas las webs afiliadas están libres de publicidad engañosa.

Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC