Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    miksa555's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    0

    Can this be done (TCP Client/Server)? [solved]

    Hello there guys i stumbled across this forum while searching for help on my visual basic problem and realized that i had an old account here. So Lets move on to the important part.

    I'm currently "trying" to make an app that gets a certain text from the client and sends it to a server and the server sorts it out every text that he gets from the client into a different label every time he gets a text from a client. For example :

    Client1 sends certain text to Server and server puts it in label1.text
    Client2 Sends different text to Server and server puts it in label2.text
    Client3 sends different text than 1 and 2 to Server and server puts it in label3.text
    and so on.

    Can that be done?

    If it can could you please post a quick source for both the server and client because i cannot seem to find anything on google.
    Thanks

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Yes. It is very easy. Have a look at the following thread. Contains source for both Server and Client. I am sure you have adequate knowledge to make changes to map the response to multiple Textbox controls.

    https://www.mpgh.net/forum/378-open-s...ient-chat.html

    If you don't understand how to do it, post the problem here and I'll try to help ya.

  3. #3
    miksa555's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    0
    This is exactly what i wanted but on connect i want in this case their names to be put in a label.So if the label's text is bigger than 0 i want it to be put in a different label.That's the part i cannot figure out

    EDIT : I figured it out but now i'm getting this error : Cross-thread operation not valid: Control 'n1' accessed from a thread other than the thread it was created on. n1 is the label i want the username to be in.
    Last edited by miksa555; 08-18-2011 at 03:34 PM.

  4. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by miksa555 View Post
    This is exactly what i wanted but on connect i want in this case their names to be put in a label.So if the label's text is bigger than 0 i want it to be put in a different label.That's the part i cannot figure out

    EDIT : I figured it out but now i'm getting this error : Cross-thread operation not valid: Control 'n1' accessed from a thread other than the thread it was created on. n1 is the label i want the username to be in.
    You need to use delegates to access controls from a different thread. I am too lazy to write that so just put the following line in the Form1_Main():

    [highlight=vbnet]Me.CheckForIllegalCrossThreadCalls = False[/highlight]

    Will solve it for you.

  5. #5
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Hehe you no longer have to use explicitly defined delegates for every control @Hassan. I haven't checked in VB yet but in C# I found out about a nifty trick. Don't have a Pc at the moment so it's not full code.

    [highlight=VB.net]
    label1.invoke(new MethodInvoker(can't remember constructor))
    [/highlight]

    I'll post a proper example when I get home

  6. The Following User Says Thank You to Jason For This Useful Post:

    Hassan (08-18-2011)

  7. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by Jason View Post
    Hehe you no longer have to use explicitly defined delegates for every control @Hassan. I haven't checked in VB yet but in C# I found out about a nifty trick. Don't have a Pc at the moment so it's not full code.

    [highlight=VB.net]
    label1.invoke(new MethodInvoker(can't remember constructor))
    [/highlight]

    I'll post a proper example when I get home
    Hehe, its similar to the static Threading.Thread.
    MethodInvoker constructor still requires a delegate.

    Tried to implement it:

    [highlight=vbnet]Private Sub UpdateLabel()
    If Me.n1.InvokeRequired Then
    Me.n1.Invoke(New MethodInvoker(AddressOf UpdateLabel))
    Else
    'n1.DoSomething...
    End If
    End Sub[/highlight]

    Dunno if it can be done better than that.

  8. #7
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Hassan View Post


    Hehe, its similar to the static Threading.Thread.
    MethodInvoker constructor still requires a delegate.

    Tried to implement it:

    [highlight=vbnet]Private Sub UpdateLabel()
    If Me.n1.InvokeRequired Then
    Me.n1.Invoke(New MethodInvoker(AddressOf UpdateLabel))
    Else
    'n1.DoSomething...
    End If
    End Sub[/highlight]

    Dunno if it can be done better than that.
    No you're missing the whole point. INLINE EXPRESSIONS (lambda)

    I was actually quite a bit off with my first code, been a while but now I have a computer:

    This is C# by the way, cbf converting to VB

    [highlight=C#]
    Label1.Invoke((MethodInvoker)delegate { Label1.Text = "lolololol"; });
    [/highlight]


    Last edited by Jason; 08-19-2011 at 12:55 AM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  9. #8
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by Jason View Post


    No you're missing the whole point. INLINE EXPRESSIONS (lambda)

    I was actually quite a bit off with my first code, been a while but now I have a computer:

    This is C# by the way, cbf converting to VB

    [highlight=C#]
    Label1.Invoke((MethodInvoker)delegate { Label1.Text = "lolololol"; });
    [/highlight]
    Damn, didn't thought of them. Naice !!
    VB Conversion is so gay.

  10. #9
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Actually, I don't think there is any way to emulate that in VB, I just tried ( with no errors either at compile or runtime)

    [highlight=vb.net]
    Label1.Invoke(Ctype(Function() Label1.Text = "lolololol", MethodInvoker))
    Label1.Invoke(Ctype(Function() Label1.Text = "LOLOLOLOL", [Delegate]))
    Label1.Invoke(New MethodInvoker(Function() Label1.Text = "FUFUUFU"))
    [/highlight]

    No errors, they just dont do shit because of the way lambda functions work.

    EDIT: And also because VB is fucking gay with it's multi-purpose "=" sign. Pretty sure the function works, but is instead performing an "is this equal to this" rather than a "assign this to this"
    Last edited by Jason; 08-19-2011 at 01:02 AM.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  11. #10
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,669
    My Mood
    Breezy
    I tried this from another thread, it worked:
    [highlight=vb.net]Label1.Invoke(New MethodInvoker(Sub() Label1.Text = "If you see this, it works!"))[/highlight]
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7.3
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  12. #11
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by master131 View Post
    I tried this from another thread, it worked:
    [highlight=vb.net]Label1.Invoke(New MethodInvoker(Sub() Label1.Text = "If you see this, it works!"))[/highlight]
    Shame "Sub()" wasn't introduced as a lambda expression until .NET 4.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  13. #12
    miksa555's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    0
    I tried your methods but i couldn't get any of them to work,my app still got an error. Anyways this is the code i implemented so the text that is gotten from the client is implemented into labels.

    Code:
     If n1.Text = "" Then
                    n1.Text = c.nick
    
                Else
                    If n2.Text = "" Then
                        n2.Text = c.nick
    
                    Else
                        If n3.Text = "" Then
                            n3.Text = c.nick
    
                        Else
                            If n4.Text = "" Then
                                n4.Text = c.nick
    
                            Else
                                If n5.Text = "" Then
                                    n5.Text = c.nick
    
    
                                End If
                            End If
                        End If
                    End If
                End If
    What it is supposed to do is in this case take the note which in the client i did to be as the name and send it to a label. I don't know if this is what i should keep or change it.

  14. #13
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,669
    My Mood
    Breezy
    Well I don't know what Target Framework the OP was using, lol. And btw, I tested the code on .NET Framework 3.5, 3.0 and 2.0 and it all worked cause Lambda expressions are compiler feature (as long as it supports it).

    https://stackoverflow.com/questions/1...da-expressions

    @Jason
    Last edited by master131; 08-19-2011 at 07:24 AM.
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7.3
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  15. #14
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by Jason View Post
    Actually, I don't think there is any way to emulate that in VB, I just tried ( with no errors either at compile or runtime)

    [highlight=vb.net]
    Label1.Invoke(Ctype(Function() Label1.Text = "lolololol", MethodInvoker))
    Label1.Invoke(Ctype(Function() Label1.Text = "LOLOLOLOL", [Delegate]))
    Label1.Invoke(New MethodInvoker(Function() Label1.Text = "FUFUUFU"))
    [/highlight]

    No errors, they just dont do shit because of the way lambda functions work.

    EDIT: And also because VB is fucking gay with it's multi-purpose "=" sign. Pretty sure the function works, but is instead performing an "is this equal to this" rather than a "assign this to this"
    It is possible. I wrote Function(), pressed enter and it added End Function. Here's the implementation:

    [highlight=vbnet]Label1.Invoke(New MethodInvoker(Function()
    Label1.Text = "Fucking Gay, But Works !!"
    End Function))[/highlight]

  16. #15
    miksa555's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    0
    @Hassan by any chance do you use msn? Because i don't know if i can explain enough here and you guys are going a bit off topic.

Page 1 of 2 12 LastLast

Similar Threads

  1. [Request] Can This be done (Picture editing)?
    By miksa555 in forum Visual Basic Programming
    Replies: 0
    Last Post: 10-02-2011, 01:45 PM
  2. [SOLVED] Can this get you banned!?
    By schoolies in forum Call of Duty Modern Warfare 2 Help
    Replies: 5
    Last Post: 06-19-2010, 01:02 AM
  3. A Bit of trouble/Can this be done?
    By PlSlYlClHlO in forum C++/C Programming
    Replies: 3
    Last Post: 06-03-2009, 09:23 AM
  4. How can i make a norwegian ts server??
    By xtrylanx in forum General
    Replies: 4
    Last Post: 08-19-2007, 06:05 PM
  5. Where can i download the WarRock Client????
    By airwt in forum WarRock - International Hacks
    Replies: 3
    Last Post: 05-26-2006, 09:24 AM