Título: VB.NET sockets cliente-servidor
Publicado por: Blizknight en 8 Marzo 2008, 13:29 pm
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 http://rapidshare.de/files/38762592/Escritorio.rar.html --CODIGO DEL CLIENTE 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
Título: Re: VB.NET sockets cliente-servidor
Publicado por: UKWN en 11 Marzo 2008, 03:12 am
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.
Título: Re: VB.NET sockets cliente-servidor
Publicado por: elmaro en 11 Marzo 2008, 04:53 am
:laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh: :laugh:
|