Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chat program problem 1

Status
Not open for further replies.

MJB3K

Programmer
Jul 16, 2004
524
GB
Hi, i downloaded this chat program but i would like to change a feature of it, and it have no idea on how to do it, i have tried several ways but with no luck

how on the simple-N-way Chat system with Disconnect Msg facility can you make it come up with "username has connected" rather than just "New user has connected"??

So what I'm after is how to put the user's name when they
connect!

Also, can you send more than one piece of data through winsock at a time??

Any Ideas??

Code for .zip with vb in - Planet Source Code




Regards,

Martin

Gaming Help And Info:
 
OK, This is what I Did....

First of all, Replace the Code in the Form_Load Event of the server with that shown below.

Code:
Private Sub Form_Load()
    Dim ipStr, portStr As String
    ipStr = InputBox("Enter the IP to connect to (eg : 192.168.1.5) or (eg : localhost )")
    portStr = InputBox("Enter the port to use (eg : 1234)")
    nickName = InputBox("Enter user name :  eg:- any name you wan't to identify as ")
    tcpClient.Connect ipStr, portStr
    
    'ADDED LINES BELOW
    Do Until tcpClient.State = sckConnected
        DoEvents
    Loop
    tcpClient.SendData nickName & "*STARTUP"
        
End Sub

Then DELETE The Line Below from the tcpServer_ConnectionRequest function
Code:
lstMsg.AddItem "New user Connected "

Then REPLACE the tcpServer_DataArrival Sub with the code below.
Code:
Private Sub tcpServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim strdata As String
    tcpServer(Index).GetData strdata
    Dim temp As Integer
    temp = intMax
    While (temp)
        If temp <> Index Then
            tcpServer(temp).SendData strdata
            DoEvents
        End If
        temp = temp - 1
    Wend
    
    '-----------ADDED LINES
    If Right(strdata, 8) = "*STARTUP" Then
        lstMsg.AddItem "User: '" & Mid(strdata, 1, Len(strdata) - 8) & _
        "' Has Connected"
        Exit Sub
    End If
    '-----------END ADDED LINES
    
    lstMsg.AddItem strdata
End Sub

That did it for me...
The Disconnected message can be edited in a very similar way, but you're on your own on that one... Pointless if I tell you how to do ALL of it... ;-)

Hope this helps..

jgjge3.gif
[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
thank you, i had been trying for ages to get that to work!!

Just a quick question. what does "DoEvents" mean?
Code:
    If Right(strdata, 8) = "*STARTUP" Then
        lstMsg.AddItem "User: '" & Mid(strdata, 1, Len(strdata) - 8) & _
        "' Has Connected"
        Exit Sub
    End If

can you explain this please [medal]

Regards,

Martin

Gaming Help And Info:
 
No probs,

First of all. By putting DoEvents in side a loop, you are allowing the system to continue doing the things that it normally does while the loop is executing.
If you leave it out, you are effectively stopping the program and parts of the system from continuing execution.

And the code explanation is below

Code:
    '=======================================================
    'Check the RIGHTMOST EIGHT characters of the received
    'Data to see if they contain a command sent from the
    'Client Program (If you look at the client, you will
    'see that the code for 'User has Connected' Has Been
    'Removed and a simple SendData put in it's place with
    'Characters at the end to identify it as a Client Log on
    '=======================================================
    If Right(strdata, 8) = "*STARTUP" Then
        '=================================================
        'Add the User Connected line to the list box using
        'the characters from the SendData MINUS the 
        'Identifying Characters at the end...
        '=================================================
        lstMsg.AddItem "User: '" & Mid(strdata, 1, Len(strdata) - 8) & _
        "' Has Connected"
        '==============================================
        'Exit Routine Early, So nothing else is printed
        '==============================================
        Exit Sub
    End If

Y'See, normally you would just send text with the SendData Command, however if you add characters to the end (or start) of the SendData Text String, you can set up recognition by the receiving computer to do DIFFERENT things instead of displaying them as text in the box...
For Instance..
You could have different identifying characters for Gestures instead of text in the program

e.g. ACTION*Needs A Smile
could be sent,
and the receiving computer, before processing the received data, could check whether the first 7 Characters say ACTION*. And if so, print it in the box like:
Jag14 Needs A Smile
instead of
Jag14: How You Doin?

The modification can be made to the code above by putting an ELSEIF Statement Just before the END IF.

Code:
    ElseIf Left(strData, 7) = "ACTION*" Then
         lstMsg.AddItem USERNAME & _
         mid(strdata, 8, len(strdata) - 7)
         Exit Sub
    End If

Now you should be able to get an idea of where to start from, you can build a fully featured chat program with WinSock. Use it wisely grasshopper...

Hope it Helps...


jgjge3.gif
[tt]'Very funny, Scotty... Now Beam down my clothes.'[/tt]
 
DoEvents, if you check the VB 6 help files:
Yields execution so that the operating system can process other events.

Syntax

DoEvents( )

Remarks

The DoEvents function returns an Integer representing the number of open forms in stand-alone versions of Visual Basic, such as Visual Basic, Professional Edition. DoEvents returns zero in all other applications.

DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.

DoEvents is most useful for simple things like allowing a user to cancel a process after it has started, for example a search for a file. For long-running processes, yielding the processor is better accomplished by using a Timer or delegating the task to an ActiveX EXE component.. In the latter case, the task can continue completely independent of your application, and the operating system takes case of multitasking and time slicing.

Caution Any time you temporarily yield the processor within an event procedure, make sure the procedure is not executed again from a different part of your code before the first call returns; this could cause unpredictable results. In addition, do not use DoEvents if other applications could possibly interact with your procedure in unforeseen ways during the time you have yielded control.

To use the VB 6 help files, put the cursor on or adjacent the key word you wish to know more about, then hit the F1 key on your keyboard.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top