"Streaming" text in a winsock chat?
"Streaming" text in a winsock chat?
"Streaming" text in a winsock chat?
"Streaming" text in a winsock chat?
"Streaming" text in a winsock chat?
"Streaming" text in a winsock chat? "Streaming" text in a winsock chat? "Streaming" text in a winsock chat? "Streaming" text in a winsock chat? "Streaming" text in a winsock chat? "Streaming" text in a winsock chat? "Streaming" text in a winsock chat? "Streaming" text in a winsock chat?
"Streaming" text in a winsock chat? "Streaming" text in a winsock chat?
"Streaming" text in a winsock chat?
Go Back  Xtreme Visual Basic Talk > > > "Streaming" text in a winsock chat?


Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2004, 05:04 PM
jaredsr05 jaredsr05 is offline
Freshman
 
Join Date: Sep 2004
Posts: 26
Default "Streaming" text in a winsock chat?


If you've seen the Animatrix you'll have an idea of what I'm talking about. In the short where the boy is at school and is chased by agents, then kills himself, he is chatting with an unknown person on his computer. As the two parties type, the text appears on the others screen, almost as if it is streaming. There is no 'send' button of any kind.
I thought maybe i could use a text change,key up, key down, key press, or maybe even a timer, but it won't work. If i send "hello" it appears as "hhehelhellhello" in my local chat area(where i recieve data) and will not even appear in the remote person's chat area. The space is taken up in the remote chat area, as if it should be there, but no text is visible.
If anyone has any idea what I'm trying to accomplish, i would greatly appreciate their help.
Here's some code from what i attempted...
Code:
Private Sub Form_Load()
If Form1.Text1.Text = "" Then
Form1.Text1.Text = "Server"
End If
Winsock1.LocalPort = 27333
Winsock1.Listen
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Winsock1.SendData Text2.Text
Text1.Text = Text1.Text & Text2.Text
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
MsgBox Winsock1.RemoteHostIP & " has connected.", vbOKOnly, ""
Text2.Enabled = True
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Winsock1.GetData data
Text1.Text = Text1.Text & vbCrLf & data
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox "Error.", vbOKOnly, ""
End Sub
Reply With Quote
  #2  
Old 10-31-2004, 06:18 PM
b0b b0b is offline
Contributor
 
Join Date: Jul 2003
Posts: 741
Default

Your sending the entire text box, try sending just the new letter. Use the KeyPress event and send the KeyAscii value. Then use the Chr$() function to turn the number back it to a letter.
Reply With Quote
  #3  
Old 10-31-2004, 08:10 PM
Grayda's Avatar
Grayda Grayda is offline
Centurion
 
Join Date: Jun 2003
Location: Australia
Posts: 145
Default

Instead of

Code:
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Winsock1.SendData Text2.Text
Text1.Text = Text1.Text & Text2.Text
End Sub
Try:

Code:
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
Winsock1.SendData right(Text2.Text,1)
Text1.Text = Text1.Text & right(Text2.Text,1)
End Sub
That will get the last letter, which will type it out (btw I have seen the animatrix ), BUT, if you want to edit what you have type (eg if you misspell something) or if you hit delete etc., then your the last letter will be sent, and will make your letter look weird.

What would be better is:

1) Get ALL of the data instead of one word
2) Then use a for loop to slowly type it out, letter by letter.

One way is to use a timer (I know this code can be better, but it's for illustrative purposes only ):

Code:
Public Sub Timer1_Timer ()

' Our letter counter
Dim i as integer
' YourData is the stuff from your winsock. This gets the next letter
Text1.text = Text1.text & mid(YourData,i,1)
' Let it move up a letter
i = i + 1
If i => len(YourData) then Timer1.enabled = False

End Sub
Set your timer to like 100ms or something.
Using a for loop or a do loop spits out the text too fast

Hope this helps
__________________
Solid Inc. Media Productions
Reply With Quote
  #4  
Old 10-31-2004, 08:11 PM
jaredsr05 jaredsr05 is offline
Freshman
 
Join Date: Sep 2004
Posts: 26
Default

OK, they keypress seems to be my best answer, but i'm not following you on the "turning the letter back into a letter." im unfamiliar with keyascii as integer. maybe it's that i don't know the letters' corresponding codes...
thanks in advance...
Reply With Quote
  #5  
Old 11-01-2004, 06:14 AM
b0b b0b is offline
Contributor
 
Join Date: Jul 2003
Posts: 741
Default

KeyAscii is an interger that represents letters, using ascii code so if you typed 'h' into the text box KeyAscii would hold the number 104 if you pass the chr$() function the number 104 it will return 'h'. You just need to decide on whether you send the number and turn it back into a letter the otherside or convert the KeyAscii value to a letter and then send the letter.
Code:
Private Sub Form_KeyPress(KeyAscii As Integer) 'converting it first would be easier. If Winsock1.state = sckConnected then Winsock1.SendData chr$(KeyAscii) end if End Sub

There are extra things you need to take into account, like Grayda said if you want to delete letter the delete or backspace numbers will be sent, and when displayed in a text box may just look like small black square and the desired letter wouldn't have been deleted.
Reply With Quote
  #6  
Old 11-01-2004, 11:04 AM
jaredsr05 jaredsr05 is offline
Freshman
 
Join Date: Sep 2004
Posts: 26
Default Thanks!

Thanks everyone, you've really helped me a lot. I've got the general idea going and I couldn't have done it without you.
Now, any ideas on how to prevent the backspace key from showing up as a litte square.

If put an "if...then" in the key_press to detect the backspace character, could i somehow chanhe its value?
That's basic thinking, i have no real idea to go about this.

Thanks again,
Jared
Reply With Quote
  #7  
Old 11-01-2004, 11:12 AM
iane87 iane87 is offline
Junior Contributor
 
Join Date: Mar 2004
Posts: 224
Default

Trying to send just one letter would be a pain plus the user might select the whole textbox and delete it all. Or paste something. I would do it like this:

Code:
Dim LastKeyIsEnter As Boolean Private Sub Form_Load() Winsock1.LocalPort = 27333 Winsock1.Listen End Sub Private Sub Text2_Change() If LastKeyIsEnter = False Then Winsock1.SendData Text2.Text If Text2.Text = "" Then: Winsock1.SendData "Ä" End If End Sub Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Winsock1.SendData "§" Text1.Text = Text1.Text & Text2.Text & vbCrLf LastKeyIsEnter = True Text2.Text = "" Else LastKeyIsEnter = False End If End Sub Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> sckClosed Then Winsock1.Close Winsock1.Accept requestID MsgBox Winsock1.RemoteHostIP & " has connected.", vbOKOnly, "" Text2.Enabled = True End Sub Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim data As String Winsock1.GetData data If data = "§" Then Text1.Text = Text1.Text & Label1.Caption & vbCrLf Label1.Caption = "" ElseIf data = "Ä" Then Label1.Caption = "" Else Label1.Caption = data End If End Sub Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean) MsgBox "Error.", vbOKOnly, "" End Sub

This way you would see what the other user is typing in label1 then once he presses enter it will show up in text1 the way most im conversations do.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
&quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat? &quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat?
 
&quot;Streaming&quot; text in a winsock chat?
&quot;Streaming&quot; text in a winsock chat?
 
-->