Coding Thread, Visual Basic 2008 LAN Chat Room in Coding and Web Development; I am currently a student at Sentinel Career Center's CCNT program (Computer Communications Network Technician). I was hoping to get ...
I am currently a student at Sentinel Career Center's CCNT program (Computer Communications Network Technician). I was hoping to get some help making a simple chat room using visual basic from scratch. It has previously been suggested to me that I should use c4f p2p toolkit to do this. What fun is that though? I want to make it without outside programs but i havn't a clue how to make the chat room run in my classes LAN. No, I am not using this for evil, netsend in our class is not disabled (this was from another post I saw earlier I just wanted to clarify this). I want a simple program to display usernames and messages next to them that say 3 people viewing my program could read.
could you please give me some general direction as to what things i will need to look up to make this work.
I'm not looking for someone to write the code for me just to tell me what I would need to research and put the code together.
here is a simple layout of the program when it is run (what I hope it will be like)
[chat room -  x ]
|user 1: hello |
|user 2: how are you user 1 and user 3? |
|user 3: i'm ok its a good thing they helped you on |
| edugeek.net forums |
|user 1: yea. |
| [Send] |
Something to that effect.. i hope it doesnt make all that spaced out and ruined that took me a decent amount of time to draw out :\
anyways I would appreciate any direction that you can give me, and please i dont want any downloads i want to code this myself i just need general direction on what i would need to do to make this work.
I'm not that hot on VB, but I code C/C++/C#/Perl/PHP/ASM
I'll go over the design/theory of the thing (applies to whatever language you may be using), but I won't list source codes (else I may as well be handing over a copy of mIRC).
Firstly, you need to read up on SOCKETS. If it's a windows app, winsock should be right up your street. Sockets are what allow you to do the raw networking stuff.
There are two types of sockets: Blocking and Non-Blocking. A blocking socket will sit and wait for data to recv() or send(), whereas non-blocking sockets use select() in order to see if theres data to be written/read and does so asynchronously.
There's tutorials on the web for this sort of thing, go google.
You need to decide what sort of sockets to use in your program.
Additionally, You will want to consider how your app is going to function. Is it peer-to-peer, or is it client-server model? The easiest model to code for conceptually is client-server. At any rate, your network code will be shaped around your design decisions at this stage.
If you choose the client-server model you will need to consider making two applications (obviously). The server will need to handle multiple connections (often simultaneously).
Thus, a blocking socket would be insufficient. (For example: Server waits infinitely for a line of text from client A, client B sends some text, but server is still waiting for client A, so nobody gets an update until client A talks).
To do this you need to do one of the following:
Use Select() and non-blocking sockets.
Use Multithreading (pthreads or microsoft threads) to spawn a 'worker thread' to handle that client exclusively (using a blocking socket), the thread provides "simultaneous" processing power as to prevent the other users from being blocked. Threads of course require you to be careful with design to ensure you don't end up causing deadlock or causing issues (resources are shared in the program, so writing to a variable not intended exclusively for a thread will change for ALL other threads, causing inconsistency if it's not policed).
Now that you know what sort of tech you're looking at, you now need to design your app. Yes, design. At the least, make a finite state machine for your program(s) designing what states your program can get into.
You will also need to design your networking protocol. It's quite likely you'll use TCP/IP for this (UDP is unreliable, but faster/less overhead, chances are you'll want the reliability of TCP for an app like this since it is quite lightweight, unlike a game).
Ontop of that layer of the OSI model (go google) you'll be writing your own protocol. This is to handle the message interaction between client-server and server-client. E.g.
Client sends message like so:
[USERNAME] - the first byte (0) indicates user is logging in/renaming to subsequent bytes in [USERNAME]
[MESSAGE] - the first byte (1) indicates user is sending a message to everyone in the chat
[USERNAME][MESSAGE] - the first byte (2) indicates the user is sending a whisper to a user. The username is specified up to the binary value of 0x1, and then the message is listed up to the end of transmission.
As you can see, you need to put a lot of thought and design into this, plus have a decent understanding of network programming.
Topics for you to research:
Finite State Machines
Sockets / Winsock
Last edited by Friez; 21st November 2008 at 09:17 AM.