![]() |
|
[.NET] Create a websocket connection - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Create a websocket connection (/showthread.php?tid=6035784) |
Create a websocket connection - SIM-2362662 - Dec 26, 2019 I've been struggling with this for the last week. Anyone has some advices on how to do it? Basically I have a website that connects with the browser using a websocket connection and start exchanging data. I want to reproduce that in my vb.net program. How can I do that? From my research I know I need to initiate a GET request at first and upgrade it to websocket. Should I use the Chilkat library? (thats what I've found on google, but I was not able to use it) Or maybe I should use the System.net.websocket namespace? (again I tried and I cant understand how to use it) I appreciate any help. Thanks! 🤝 RE: Create a websocket connection - Charger - Dec 26, 2019 This would be a lot easier outside of Vb.net. Do you HAVE to do it in .net? https://www.example-code.com/vbnet/websocket_send_receive_frames.asp I’d start with that RE: Create a websocket connection - SIM-2362662 - Dec 26, 2019 (Dec 26, 2019 10:34 AM)Charger Wrote: This would be a lot easier outside of Vb.net. Do you HAVE to do it in .net? Yeah, I prefer to do it in Vb.net. What would be easier to use for this? Python? Also, I know about that. It's the Chilkat library I was talking about. But I'm having some problems with it. I was hoping for a code example or someone to answer some questions RE: Create a websocket connection - HFDone - Dec 26, 2019 https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-request-data-using-the-webrequest-class RE: Create a websocket connection - SIM-2362662 - Dec 26, 2019 (Dec 26, 2019 11:34 AM)HFDone Wrote: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-request-data-using-the-webrequest-class Nothing useful here. I'm trying to make a websocket connection, not just create a webrequest. RE: Create a websocket connection - brhack - Dec 27, 2019 Imports System.Net.Sockets Imports System.Text Module Module1 Sub Main() Dim serverSocket As New TcpListener(8888) Dim requestCount As Integer Dim clientSocket As TcpClient serverSocket.Start() msg("Server Started") clientSocket = serverSocket.AcceptTcpClient() msg("Accept connection from client") requestCount = 0 While (True) Try requestCount = requestCount + 1 Dim networkStream As NetworkStream = clientSocket.GetStream() Dim bytesFrom(10024) As Byte networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize)) Dim dataFromClient As String = System.Text.Encoding.ASCII.GetString(bytesFrom) dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")) msg("Data from client - " + dataFromClient) Dim serverResponse As String = "Server response " + Convert.ToString(requestCount) Dim sendBytes As [Byte]() = 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 clientSocket.Close() serverSocket.Stop() msg("exit") Console.ReadLine() End Sub Sub msg(ByVal mesg As String) mesg.Trim() Console.WriteLine(" >> " + mesg) End Sub End Module Imports System.Net.Sockets Imports System.Text Public Class Form1 Dim clientSocket As New System.Net.Sockets.TcpClient() Dim serverStream As NetworkStream Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim serverStream As NetworkStream = clientSocket.GetStream() Dim outStream As Byte() = System.Text.Encoding.ASCII.GetBytes("Message from Client$") serverStream.Write(outStream, 0, outStream.Length) serverStream.Flush() Dim inStream(10024) As Byte serverStream.Read(inStream, 0, CInt(clientSocket.ReceiveBufferSize)) Dim returndata As String = System.Text.Encoding.ASCII.GetString(inStream) msg("Data from Server : " + returndata) End Sub Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load msg("Client Started") clientSocket.Connect("127.0.0.1", 8888) Label1.Text = "Client Socket Program - Server Connected ..." End Sub Sub msg(ByVal mesg As String) TextBox1.Text = TextBox1.Text + Environment.NewLine + " >> " + mesg End Sub End Class RE: Create a websocket connection - SIM-2362662 - Dec 27, 2019 (Dec 27, 2019 02:34 PM)brhack Wrote: Imports System.Net.Sockets I'm not looking for a way to connect two applications through TCP... I need a way to connect through a websocket with a website. I did it in python. Idk how to do it in VB.net RE: Create a websocket connection - HFDone - Dec 28, 2019 using System.Net.Sockets; PHP Code more info https://searchitchannel.techtarget.com/feature/Winsock-NET-and-the-Compact-Framework |