FBChat

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

FBChat

Post by mrminecrafttnt »

Hi there this is a very simple Chat programm for an shared folder.

Code: Select all

open "FBChat.dat" for binary as #1

sub write_msg(msg as string)
    dim as ushort length = len(msg)
    dim as ubyte buffer(length)
    for i as integer = 0 to length-1
        buffer(i)=msg[i]
    next
    put #1,1,length
    put #1,,buffer()
end sub

function read_msg as string
    dim as string msg
    dim as ushort length
    get #1,1,length
    dim as ubyte buffer(length)
    get #1,,buffer()
    msg = space(length)
    dim as integer count
    for i as integer = 0 to length-1
        msg[i]=buffer(i)
    next
    return msg
end function

sub msgprinter (msg as string)
    static as ubyte p,c
    c+=1
    c mod = 8
    p=18+c
    locate p,1
    print msg
end sub

sub writer
    dim as string username,Message
    do
        locate 2,1
        Input "Username : ",Username
    loop until Username <> ""
    do
        do
            locate 3,1
            sleep 10
        loop until csrlin = 3 and pos = 1
        
        Input "Message : ",Message
        Message = TIME +" "+ Username + " : "+ Message
        write_msg(Message)
        sleep 1,1
    loop
end sub

sub reader
    dim as string oldmessage,newmessage
    do
        newmessage = read_msg
        if newmessage <> oldmessage then
            oldmessage = newmessage
            msgprinter newmessage
        end if
        sleep 1,1
    loop
end sub


Print "FBChat 0.1"
threadcreate (@reader)
sleep 10
threadcreate (@writer)


do
    sleep 1
loop
Post Reply