Necesito que alguien me explique como puedo realizar una conexión por sockets en VB.net, programo con Visual Basic 2008 y con Visual Studio 2010.
Lo que necesito basicamente son las peticiones GET y POST.
Saludos y gracias!
Ya lo hice gracias a un tutorial, aquí el code (sin modificar):
Imports System.Net.Sockets Imports System.Text Module Module1 Sub Main() Dim serverSocket As New TcpListener(8888) Dim clientSocket As TcpClient Dim counter As Integer serverSocket.Start() msg("Server Started") counter = 0 While (True) counter += 1 clientSocket = serverSocket.AcceptTcpClient() msg("Client No:" + Convert.ToString(counter) + " started!") Dim client As New handleClinet client.startClient(clientSocket, Convert.ToString(counter)) End While clientSocket.Close() serverSocket.Stop() msg("exit") Console.ReadLine() End Sub Sub msg(ByVal mesg As String) mesg.Trim() Console.WriteLine(" >> " + mesg) End Sub Public Class handleClinet Dim clientSocket As TcpClient Dim clNo As String Public Sub startClient(ByVal inClientSocket As TcpClient, _ ByVal clineNo As String) Me.clientSocket = inClientSocket Me.clNo = clineNo Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf doChat) ctThread.Start() End Sub Private Sub doChat() Dim requestCount As Integer Dim bytesFrom(10024) As Byte Dim dataFromClient As String Dim sendBytes As [Byte]() Dim serverResponse As String Dim rCount As String requestCount = 0 While (True) Try requestCount = requestCount + 1 Dim networkStream As NetworkStream = _ clientSocket.GetStream() networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize)) dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom) dataFromClient = _ dataFromClient.Substring(0, dataFromClient.IndexOf("$")) msg("From client-" + clNo + dataFromClient) rCount = Convert.ToString(requestCount) serverResponse = "Server to clinet(" + clNo + ") " + rCount sendBytes = Encoding.ASCII.GetBytes(serverResponse) networkStream.Write(sendBytes, 0, sendBytes.Length) networkStream.Flush() msg(serverResponse) Catch ex As Exception MsgBox(ex.ToString) End Try End While End Sub End Class End Module
Fuente
Saludos!
Listo!
Ya lo hice gracias a un tutorial, aquí el code (sin modificar):
Fuente
Saludos!