|
-
Apr 29th, 2005, 10:08 PM
#1
Thread Starter
New Member
Username problems[Resolved]
server code:
VB Code:
Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Dim strData2() As String
Dim Users() As String
Dim word1 As String
Dim word2 As String
On Error Resume Next
Socket(Index).GetData strData
strData2 = Split(strData, "/")
word1 = strData2(0)
word2 = strData2(1)
If word1 = "name" Then
Users(Index) = word2
txtMain.Text = txtMain.Text & vbCrLf & "User " & Users(Index) & " Connected with ip " & Socket(Index).RemoteHostIP
txtMain.SelStart = Len(txtMain.Text)
Else
strData = Users(Index) & ": " & strData
txtMain.Text = txtMain.Text & vbCrLf & strData
txtMain.SelStart = Len(txtMain.Text)
Dim i As Integer
For i = 1 To Socket.Count
If Socket(i).State = sckConnected Then
Socket(i).SendData strData
DoEvents
End If
Next i
End If
Client code:
VB Code:
Private Sub Winsock_Connect()
' we are connected!
lbl1.Caption = "Connected"
txtMain.Text = txtMain.Text & vbCrLf & "Connected to " & Winsock.RemoteHostIP & " on port 1007"
Winsock.SendData "name/" & USRName
DoEvents
End Sub
this code is supposed to set a username for each socket, for a chat
when the client connects, it send name/(the username) and when the server recieves data starting with name/ it sets the username in an array with the same index as the socket. when i run the program, and connect to myself, it doesn't set a name. whenever i send a message it is just the message with no username. someone help please, thanks.
edit: ignore the weird indentations in the code, it was a copy/paste problem
edit2: upon taking out the on error resume next line of code, and moving the dim Users() as string to the top of the code and not in this event, i recieved the error: "Subscript out of range"
Last edited by camman977; Apr 30th, 2005 at 12:49 PM.
-
Apr 30th, 2005, 12:22 PM
#2
Frenzied Member
Re: Username problems[Edited]
 Originally Posted by camman977
server code:
VB Code:
Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Dim strData2() As String
Dim Users() As String
Dim word1 As String
Dim word2 As String
On Error Resume Next
Socket(Index).GetData strData
strData2 = Split(strData, "/")
word1 = strData2(0)
word2 = strData2(1)
If word1 = "name" Then
Users(Index) = word2
txtMain.Text = txtMain.Text & vbCrLf & "User " & Users(Index) & " Connected with ip " & Socket(Index).RemoteHostIP
txtMain.SelStart = Len(txtMain.Text)
Else
strData = Users(Index) & ": " & strData
txtMain.Text = txtMain.Text & vbCrLf & strData
txtMain.SelStart = Len(txtMain.Text)
Dim i As Integer
For i = 1 To Socket.Count
If Socket(i).State = sckConnected Then
Socket(i).SendData strData
DoEvents
End If
Next i
End If
Client code:
VB Code:
Private Sub Winsock_Connect()
' we are connected!
lbl1.Caption = "Connected"
txtMain.Text = txtMain.Text & vbCrLf & "Connected to " & Winsock.RemoteHostIP & " on port 1007"
Winsock.SendData "name/" & USRName
DoEvents
End Sub
this code is supposed to set a username for each socket, for a chat
when the client connects, it send name/(the username) and when the server recieves data starting with name/ it sets the username in an array with the same index as the socket. when i run the program, and connect to myself, it doesn't set a name. whenever i send a message it is just the message with no username. someone help please, thanks.
edit: ignore the weird indentations in the code, it was a copy/paste problem
edit2: upon taking out the on error resume next line of code, and moving the dim Users() as string to the top of the code and not in this event, i recieved the error: "Subscript out of range"
1. First of all remove On Error Resume Next
2. You have defined Users as a dynamic Array, and i can't see any Redim Statement which creates that array...
My Suggestion
If you want to associate a username with a specific Socket.....i would recommend that you use the Tag property of Winsock control...
-
Apr 30th, 2005, 12:48 PM
#3
Thread Starter
New Member
Re: Username problems[Edited]
Ok, i will use tag, thanks
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
|