|
-
Jul 7th, 2000, 01:46 AM
#1
Thread Starter
Hyperactive Member
Ok... I am making a chat program. When the program starts... it asks for a nickname. I have the nickname to appear in the users list when connected.. but it only shows mine... I want to know how I can show theirs and mine in the users text box.... Would i associate Winsock1.remotehost with the nickname?
And the easier part...
I use this to show the text... from their bar to the room...
Code:
Dim New_Line As String
'Reset the position of the last line feed if the
'user has clear the chat window
If Trim(Text2) = vbNullString Then Last_Line_Feed = 0
'If the user pressed Enter...
If KeyAscii = 13 Then
New_Line = Mid(Text2, Last_Line_Feed + 1)
'Save the position of the current linefeed
Last_Line_Feed = Text2.SelStart
'Send the new text across the socket
Winsock1.SendData New_Line
StatusBar1.Panels(2).Text = " Sent " & (LenB(New_Line) / 2) & " bytes "
Text1 = Text2
Text2 = ""
End If
when I hit enter, it erases the users private text box (text 2) and then places the text in the chat room field. (text1) But when the other person, or I enter in another message then it erases everything in the chat window... It does this because I have it (text1 = text2). How can I make the text go to the other window without erasing the text already in there?
Help Please!
Thanks
-Sac
-
Jul 7th, 2000, 02:53 AM
#2
Fanatic Member
What I usually do is define some keywords for controlling flow. this way you can pass commands between clients and the server etc.
eg
USER> "nickname"
TEXT> "client text sent"
BOLD> "this text will appear in bold"
if you make all the keywords the same length then you can pass the text though a case statement on the left$(arrivede_Text, 5). Then you can decide what text get's displayed and what are commands. Everything the user types has "TEXT>" appended to the front of it.
Be careful what you let people do as far as files though, as you could duplicate the commands from a telnet session and send arbitrary commands. (You could use simple XOR encryption to get around this in a few lines of code though)
For the second part, can't you replace
Text1 = Text2
with
Text1 = Text1 & Text2
or
Text1 = Text2 & Text1
if you want the new text to appear on top (I'm not sure about what sort of interface you're using)
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 7th, 2000, 03:07 AM
#3
Thread Starter
Hyperactive Member
I dont really understand what you are saying about storing the user name...
-
Jul 7th, 2000, 03:15 AM
#4
Fanatic Member
Maybe I'm misunderstanding the problem. I assumed you were having problems with the clients passing their usernames to eachother.
This way a user joins, his username is sent, when each client receives it they all send their usernames to him, or double-ups can be delt with. Even in a simple chat program you need an "Out of band" (not visible to the client) means of controlling what happens, else your just sending msg text and can't really disply extra infomation about anything
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 7th, 2000, 03:19 AM
#5
Thread Starter
Hyperactive Member
no, you understood right, I just didn't really understand what I am supposed to do when you explained it. How can I let the program get the other users name?
-
Jul 7th, 2000, 03:32 AM
#6
Fanatic Member
Send it!
What are you using for the server? or is this a series of clients talking to eachother on UDP? or just two clients talking on TCP?
Can I have a bit more info please? I'm sure I can help you but we seem to be going around in circles
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jul 7th, 2000, 03:38 AM
#7
Thread Starter
Hyperactive Member
I connect using the Winsock...
They enter my address, I enter theirs, and we enter local, and remote ports... Then it uses a Winsock control to connect...
Here is the connection...
Code:
Private Sub cmdConnect_Click()
On Error GoTo ErrHandler
With Winsock1
'Set the remotehost property
.RemoteHost = Trim(txtRemoteIP)
'Set the remoteport property.
'This should be equal to the
'localhost property of the
'remote machine.
.RemotePort = Trim(txtRemotePort)
'The localport property cannot be
'changed,so check if it has already
'been set.
If .LocalPort = Empty Then
.LocalPort = Trim(txtLocalPort)
Frame2.Caption = .LocalIP
.Bind .LocalPort
End If
End With
'Make sure that the user can't change
'the local port
txtLocalPort.Locked = True
'Show the current status of the connection in
'the status bar
StatusBar1.Panels(1).Text = " Connected to " & Winsock1.RemoteHost & " "
Frame1.Enabled = True
Frame2.Enabled = True
Text2.SetFocus
Text3 = frmLogin.usernm
Exit Sub
ErrHandler:
MsgBox "Winsock failed to establish connection with remote server", vbCritical
End Sub
And here is the info the program gets from the other computer when connection is made...
Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'New_Text is the text that has just arrived
'from across the socket
Dim New_Text As String
'Get the new text
Winsock1.GetData New_Text
'Show the new text
Text1.SelText = New_Text
Frame1.Caption = Winsock1.RemoteHostIP
'Show the byte size of this transmission in the statusbar
StatusBar1.Panels(2).Text = " Recieved " & bytesTotal & " bytes "
End Sub
Did that help?
-
Jul 7th, 2000, 04:41 AM
#8
Fanatic Member
ok, now go and read the first post I wrote.
you need communication to be happening between the two clients other than the chat text. so, have specific commands. If the incoming text has "TEXT>" in front of it (for example) then put it into the text box, if the text has "USER>" infront of it then put it in the user list box. you could also have "HTTP>" and send a link and the other persons browser could automatically be sent to the site.
when text is sent then its Winsock.senddata "TEXT>" & Chat text or winsock.senddata "USER> & Username
This is a simplificate on how a lot of higher protocals work, likt html, the browser sees a text tag and has a command attached to that, your client sees a "USER>" tag and knows that the following text is the username...
Do you get what I'm saying?
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|