Results 1 to 7 of 7

Thread: Simple Multi User TCP Chat Using Sockets?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2018
    Posts
    156

    Simple Multi User TCP Chat Using Sockets?

    I have been searching high and low for vb .net chat examples and they all seem very difficult to understand for me. All I want to do is have a form for the server that will listen for the client and connect the users so they can chat together. The server form would have start server button, a textbox or label for messages such as "Server Started", after clicking Start Server Button and "UserName Connected" when a user connects to the server..

    The client form would have a button to connect to the server and a textbox for IP address and another for the port number to connect to..

    If anyone could help me with this very basic example I would really appreciate it. I just do not want to look at anymore example projects or youtube tutorials.
    They all seem too advanced adding all kinds of stuff like classes and other stuff. I just need the most basic working example for now and I will try to work it up as I go.

    Thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,957

    Re: Simple Multi User TCP Chat Using Sockets?

    As I mentioned in your other thread, follow the CodeBank link in my signature below and check out my thread on Asynchronous TCP. The point of that thread was to demonstrate how to use the TcpClient class with asynchronous method calls and a chat app was used to demonstrate. Don't expect it to be too simple though. Asynchronous programming of any sort is inherently more complex than synchronous equivalents and you really need to be using parallelism in this case. Also, if you're seriously trying to avoid "all kinds of stuff like classes and other stuff" then I'm afraid this project is too complex for you right now. The idea that you can create a multi-user client/server chat app inside a form is just silly. It could be done but it would be a total mess and much harder to work out what was going on. Classes are one of the bedrock features of OOP and VB.NET is an OO language so you're actually fighting against the language if you're trying to avoid them. It's actually impossible to avoid them anyway because every form is itself a class. Just learn how to use VB properly. Now is the best time to do that.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2018
    Posts
    156

    Re: Simple Multi User TCP Chat Using Sockets?

    ok Thanks I have downloaded that project you have made but it is throwing an error:

    "A project with an Output Type of Class Library cannot be started directly."

    Yes this chat project is not going to be simple I can tell.. I am in for a ride with this but it is better to learn than to try to take shortcuts.
    I am sorry about the other day, I had been searching and downloading all the chat examples I could find and still was very confused and frustrated that I could not find one simple way of doing it.
    I know there is a simple way because I have seen it done before. I lost the example I once had in vb6.. but vb .net is different in how this works. No winsock control.. isn't it still winsock though? They just changed the name in vb .net? So I am sorry about being frustrated and saying that I wanted to avoid "classes and other stuff" I was just upset about not being able to find a simple example of TCP Listen and having a client connect.

    I think the best thing for me right now is to find a good programming book on this topic. If you know any please send me a recommendation as trying to learn on the internet sometimes can be very aggravating.

    I think books are easier to understand since it takes you step by step through everything.
    Object Orientated Programming, yes I remember but yes I need to learn and relearn the basics.

    If you know or anyone else knows a good book on VB .Net Internet Programming, things like Asynchronous TCP Connections, Chat Clients, Messaging, File Transfer, Email.. etc please let me know.

    Thanks

  4. #4
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,034

    Re: Simple Multi User TCP Chat Using Sockets?

    https://www.amazon.com/Network-Progr.../dp/1555583156

    Caveat - this book was published in 2004 for Visual Studio 2003. Amazon lets you "Look inside" the book, so you can see what topics are covered.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,957

    Re: Simple Multi User TCP Chat Using Sockets?

    Quote Originally Posted by DreamWarrior77 View Post
    ok Thanks I have downloaded that project you have made but it is throwing an error:

    "A project with an Output Type of Class Library cannot be started directly."
    So don't try to start a library project directly. Set the startup project(s) for the solution to start the project(s) you want to start rather than just the current project. Needing that advice is an inauspicious start. I would have had both the server and client app projects selected for startup originally but I may have deleted the user file that stores that information.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,957

    Re: Simple Multi User TCP Chat Using Sockets?

    Quote Originally Posted by DreamWarrior77 View Post
    I know there is a simple way because I have seen it done before. I lost the example I once had in vb6.. but vb .net is different in how this works. No winsock control.. isn't it still winsock though? They just changed the name in vb .net?
    "Winsock" is short for "Windows sockets" which is the underlying technology built into the OS. From that perspective, you are still using winsock in VB.NET and there is a Socket class that corresponds directly to a Windows socket, with the TcpClient being a higher-level abstraction and containing a Socket internally. As is often the case in VB6, the Winsock control was a monolith that put all sorts of related functionality into one place. That means power but also (internal) complexity and/or (external) inflexibility. The .NET way is the OO way, i.e. more types that are smaller and more focused on specific tasks within the whole. Get used to it. The same is true in many cases, e.g. instead of doing all your data access with a Recordset you use multiple objects that are each responsible for a specific part of the job, e.g. DbConnection, DbCommand, DataTable, etc. You could absolutely build something like the VB6 Winsock control in VB.NET using other classes internally - many people may already have done so - and then use it any place you needed the same type of functionality but the .NET Framework doesn't provide that natively.

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,024

    Re: Simple Multi User TCP Chat Using Sockets?

    VB6 didn't deal directly with multi-threading and asynchrony. You could do multi-threading, but it was hidden as much as possible. This had advantages and disadvantages when it came to networking. The advantage was that it was simple to do simple things The disadvantage was largely that you HAD to do simple things.

    I don't believe that I ever dealt with TCP communications in VB6, but I did deal with UDP communications. TCP makes much more sense being threaded, because it is reasonable for a server to have multiple simultaneous connections, and each of them will naturally block the program for some period of time, so having those connections each in different threads makes sense. They can go ahead and block the thread they are on without impacting anything else. Since TCP is so naturally threaded, it was a bit of a contortion for VB6. When it came to UDP, you have a similar problem, except that EVERY system is a server, so every system deals with threading issues. Yet VB6 did not deal with threading. What happened was that whenever a message was received, an event was raised on the UI thread with the packet. That's a very simple and easy way to interact with UDP messages. Of course, it had issues if the UI thread wasn't ready to receive the packet right then. If it was busy, it would get around to it when it had time. Therefore, your communication had to recognize that it might not happen right away.

    The point is that VB6 was simple because it had to be, not because the problem was simple. What VB6 was doing was restricting what you could do such that all you could do was simple enough to fit within the VB6 model. People have extended that model, but that is NOT simple. In fact, it is harder to do that .NET.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width