Hello There, Guest!
View New Posts  |  View Today's Posts
[VB.Net] Asynchronized Server/Client Demo(using sockets)

ii 
  • 1 Vote(s) - 5 Average


06-07-2011, 02:10 PM #1
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

Asynchronized Server/Client Demo(using sockets)
This is a quick tutorial that I made for SF. I will re-upload the video since it mentions SF in the opening line. But members here can still learn from it.

This tutorial demonstrates how EASY it is to use Sockets. This is my first vid so bear with me. It ran a little long but it covers both Server and Client. This demonstrates a single client connection. I plan on releasing another vid later today exclusively for TLF demonstrating how to create a server with multiple clients. [Edit: Video link here]

What is this?
This is a demonstration on how to use Sockets when programming Server/Client applications. It can be used in chat programs, naughty black hat stuff, IRC clients etc.

Can I c/p your code?
Sure why not, it is up to you to learn from this. You get only from this what you put in. So if you actually go through the code and understand it, you will learn far more than c/p'ing.

Video:



Server Code:
Code:
Imports System.Net, System.Net.Sockets
Public Class frmServer
    Dim server As Socket
    Dim client As Socket
    Dim bytes As Byte() = New Byte(1023) {}
    Private Sub frmServer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Dim xEndpoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 6969)
        server.Bind(xEndpoint)
        server.Listen(2)
        server.BeginAccept(New AsyncCallback(AddressOf OnAccept), vbNull)
    End Sub
    Private Sub OnAccept(ByVal ar As IAsyncResult)
        client = server.EndAccept(ar)
        client.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, New AsyncCallback(AddressOf OnRecieve), client)
    End Sub
    Private Sub OnRecieve(ByVal ar As IAsyncResult)
        client = ar.AsyncState
        client.EndReceive(ar)
        client.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, New AsyncCallback(AddressOf OnRecieve), client)
        Dim message As String = System.Text.ASCIIEncoding.ASCII.GetString(bytes)
        MessageBox.Show(message)
    End Sub
End Class

Client Code:
Code:
Imports System.Net, System.Net.Sockets
Imports System.Text.ASCIIEncoding
Public Class frmClient
    Dim client As Socket
    Dim host As String = "127.0.0.1"
    Dim port As Integer = "6969"
    Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
        client = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Dim IP As IPAddress = IPAddress.Parse(host)
        Dim xIpEndPoint As IPEndPoint = New IPEndPoint(IP, port)
        client.BeginConnect(xIpEndPoint, New AsyncCallback(AddressOf OnConnect), Nothing)
        btnConnect.Enabled = False
    End Sub
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        Dim bytes As Byte() = ASCII.GetBytes(txtMessage.Text)
        client.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, New AsyncCallback(AddressOf OnSend), client)
    End Sub
    Private Sub OnConnect(ByVal ar As IAsyncResult)
        client.EndConnect(ar)
        MessageBox.Show("Connected")
    End Sub
    Private Sub OnSend(ByVal ar As IAsyncResult)
        client.EndSend(ar)
    End Sub

End Class

*Hey RDCA notice the bold?
Cool
This post was last modified: 06-08-2011, 01:46 PM by KoBE.

06-08-2011, 01:31 PM #2
alecn1519
Game Developer
**
Posts: 191 Threads:17 Joined: Jun 2011 Reputation: 13

RE: Asynchronized Server/Client Demo(using sockets)
Very nice tutorial. I am glad to say I was able to follow everything and convert to C# on the go.
My Themes | Have a new computer


06-08-2011, 01:44 PM #3
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: Asynchronized Server/Client Demo(using sockets)
(06-08-2011, 01:31 PM)alecn1519 Wrote:  Very nice tutorial. I am glad to say I was able to follow everything and convert to C# on the go.

Sweet! I have another vid going over Multiple clients, but I dont do any talking. It just shows the steps to create it.
http://techlifeforum.net/showthread.php?tid=86

06-08-2011, 05:23 PM #4
Sam Baker
I LOVE TLF!!!
*****
BSOD Crew
Posts: 1,525 Threads:76 Joined: Jun 2011 Reputation: 40

RE: Asynchronized Server/Client Demo(using sockets)
If you kept making similar videos on how to make a rat series it will be MUCH better than xSilent's
And will get a huge traffic specially if you posted it here and posted the thread links on HF :)
Now i am become death,The destroyer of worlds ~oppenheimer


06-17-2011, 01:39 AM #5
ReDDeMiSe
Member
**
Posts: 85 Threads:12 Joined: Jun 2011 Reputation: 3

RE: Asynchronized Server/Client Demo(using sockets)
Hey Kobe,

This will help me alot for my internship. By any chance have the source file?

I need help:

I need to learn how to code a Client/Server to talk to each other... to send data back in forth not only from client to server... any tutorials ?

06-17-2011, 01:51 AM #6
alecn1519
Game Developer
**
Posts: 191 Threads:17 Joined: Jun 2011 Reputation: 13

RE: Asynchronized Server/Client Demo(using sockets)
He posted the source right there, under the video.
My Themes | Have a new computer


06-17-2011, 09:13 AM #7
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: Asynchronized Server/Client Demo(using sockets)
(06-17-2011, 01:39 AM)ReDDeMiSe Wrote:  Hey Kobe,
This will help me alot for my internship. By any chance have the source file?
I need help:
I need to learn how to code a Client/Server to talk to each other... to send data back in forth not only from client to server... any tutorials ?

As alecn stated, the source is under the vid. There are only a few controls you need to add to the form so a project file wouldnt help you much.
Let me know what kind of data you are sending and I may be able to through together something.
This post was last modified: 06-17-2011, 09:13 AM by KoBE.

06-17-2011, 05:03 PM #8
ReDDeMiSe
Member
**
Posts: 85 Threads:12 Joined: Jun 2011 Reputation: 3

RE: Asynchronized Server/Client Demo(using sockets)
(06-17-2011, 09:13 AM)KoBE Wrote:  
(06-17-2011, 01:39 AM)ReDDeMiSe Wrote:  Hey Kobe,
This will help me alot for my internship. By any chance have the source file?
I need help:
I need to learn how to code a Client/Server to talk to each other... to send data back in forth not only from client to server... any tutorials ?


Thank you for getting back to me...

So my task is to ideally create:
UDP socket?

That Client would Send the server values such as
LeftHandSensor=30.4
and the server saves these information as a 'txt' or 'ini'
so I can have my c++ program on linux import them as arrays.
your probably wondering why VBnet because I can compile this on Linux or MacOS using mono-project.
I saw your tutorial and figured it would be the easiest way to get it done?

then i would like the server to gather log files from my c++ program and sending it to the client and creating a real life time plot...

Do you have any suggestions? or how I can go about doing this

Or maybe have a Windows (GUI VBNET) talk to a Linux C code? I don't know I'm confused and im new to all this. thanks for your help

red

As alecn stated, the source is under the vid. There are only a few controls you need to add to the form so a project file wouldnt help you much.
Let me know what kind of data you are sending and I may be able to through together something.


06-17-2011, 05:18 PM #9
HSP
Privacy is dead...
**
Posts: 169 Threads:16 Joined: Jun 2011 Reputation: 12

RE: Asynchronized Server/Client Demo(using sockets)
(06-08-2011, 05:23 PM)Hell Guardian Wrote:  If you kept making similar videos on how to make a rat series it will be MUCH better than xSilent's
And will get a huge traffic specially if you posted it here and posted the thread links on HF :)

Only problem with making a RAT is that it would go against site policies.

Even if it's for educational purposes and didn't include any real functions it's just a matter of time before the kiddies CnP random stealer functions and such into it and voila we've successfully contributed to making the internet an even worse place.
--- HSP a.k.a HSPSoftware ---

06-17-2011, 05:22 PM #10
Sam Baker
I LOVE TLF!!!
*****
BSOD Crew
Posts: 1,525 Threads:76 Joined: Jun 2011 Reputation: 40

RE: Asynchronized Server/Client Demo(using sockets)
Nope RATs are Ok as long it doesn't have spreading functions ^^
Now i am become death,The destroyer of worlds ~oppenheimer



ii 


Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
   Create your own IRC Client [C#/VB.Net] KoBE 185 120,209 10-01-2016, 06:57 PM
Last Post: AceInfinity
   IRC Client Class KoBE 110 74,339 10-01-2016, 06:52 PM
Last Post: AceInfinity
Star  Multi-Client Server Async Socket Example KoBE 165 168,190 09-10-2016, 05:17 AM
Last Post: R4TK3N
  Telnet Client AceInfinity 5 2,795 06-05-2016, 07:48 PM
Last Post: AceInfinity
   Twitch chat bot (irc client) dmgvol 11 19,319 08-24-2015, 11:59 PM
Last Post: Signal_20


Users browsing this thread: 1 Guest(s)