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:
[0][USERNAME] - the first byte (0) indicates user is logging in/renaming to subsequent bytes in [USERNAME]
[1][MESSAGE] - the first byte (1) indicates user is sending a message to everyone in the chat
[2][USERNAME][1][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
- OSI Model
- Sockets / Winsock
- Multi Threading
- TCP/UDP
Good luck!



LinkBack URL
About LinkBacks
Reply With Quote
