I am a newbie to VB...and i am doing a project on One to many chat using the winsock component...the only problem i am stuck with now is that i have completed only one to one chat and would like to make it a many to many chat...plz help me out in this....also i would like to insert the video conferencing facility but since time is short i wud be greatfull if i got a fully commented code for the same....thanx alot...plz mail me at varun.coolmax@gmial.com ASAP

Recommended Answers

All 6 Replies

post wat uve done so far and ill explain many to many

post wat uve done so far and ill explain many to many

Client Side

Private Sub cmdConnect_Click()
On Error GoTo handle_connection_error


cmdDisconnect.Visible = True
cmdConnect.Visible = False


Winsock1.Close
'We close it in case it was trying to connect OR is previously connected

Winsock1.RemoteHost = "192.168.1.18"
' The Host IP of the Principal will be predefined


'Assigning text of IP to winsock's remote host
'txtIP can contain both hostnames ( like [url]www.google.com[/url] ) or
'IPs ( like 127.0.0.1 )

Winsock1.RemotePort = "123"
'The Principal's Port no. will be predeffined

'Assigning text of port to winsock's remote port
'Set the port we want to connect to ...
'The server must be listening on this port too ...
                            
Winsock1.Connect
'Try to connect to the server.

Exit Sub

handle_connection_error:
'Handle any connection errors
MsgBox "Error : " & Err.Description, vbCritical

End Sub

Private Sub cmdDisconnect_Click()
'Close the connection to the Server
cmdDisconnect.Visible = False
cmdConnect.Visible = True

Unload Me
frmWelcome.Show

End Sub

Private Sub cmdSend_Click()
'To send the data to the server &
'also to display the same in the main chat console

On Error GoTo handle_send_data

Winsock1.SendData txtTempString.Text
'The string of text will be sent.

rtbMainChat.Text = rtbMainChat.Text & "Client : " & txtTempString.Text & vbCrLf
'We have send the data to the server but
'we also need to add them to our Chat Buffer (Main chat console)

rtbMainChat.SelStart = Len(rtbMainChat)
'This is used to autoscroll down the Main Chat Console

txtTempString.Text = ""
'Clear the text for entering new data ...

Exit Sub

handle_send_data:
'Handle send data errors
MsgBox "Error : " & Err.Description, vbCritical

End Sub



Private Sub Winsock1_Connect()
'This event is triggered when the connection is made sucessfully
'with the server

'Winsock1.RemoteHost returns the hostname( or ip ) of the host
'Winsock1.RemoteHostIP returns the IP of the host

rtbMainChat.Text = "Sucessfully Connected to " & Winsock1.RemoteHostIP & ", through port = " & Winsock1.RemotePort & vbCrLf

rtbMainChat.SelStart = Len(rtbMainChat)
'This is used to autoscroll down the Main Chat Console

End Sub

Private Sub Winsock1_Close()
'This event handles closes of winsock connection

Winsock1.Close
'Closes the winsock connection

rtbMainChat.Text = rtbMainChat.Text & "*** Disconnected" & vbCrLf
'Displays the disconnected connection

rtbMainChat.SelStart = Len(rtbMainChat)
'This is used to autoscroll down the Main Chat Console

End Sub


Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'This is being trigger every time new data arrive
'we use the GetData function which returns the data that winsock is holding

Dim strString As String
'This is the string where the incomming data is saved

Winsock1.GetData strString, vbString
'Writes the new data in our string strString( string format )

rtbMainChat.Text = rtbMainChat.Text & "Server : " & strString & vbCrLf
'Add the new message to our chat buffer

rtbMainChat.SelStart = Len(rtbMainChat)
'This is used to autoscroll down the Main Chat Console

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)
'this event is to handle any kind of errors occuring while using winsock

'Number gives you the number code of that specific error
'Description gives you string with a simple explanation about the error


rtbMainChat.Text = rtbMainChat.Text & "*** Error : " & Description & vbCrLf
'Append the error message in the chat buffer

rtbMainChat.SelStart = Len(rtbMainChat)
'This is used to autoscroll down the Main Chat Console

Winsock1_Close
'Close the connection

End Sub


Private Sub cmdVidClose_Click()
'minimizes the form to exclude the Video Control
frmPrincipal.Width = "8900"
cmdVidClose.Visible = False
cmdVidOpen.Visible = True

End Sub

Private Sub cmdVidOpen_Click()
'Widens the form to Include the Video Control
frmPrincipal.Width = 13230
cmdVidClose.Visible = True
cmdVidOpen.Visible = False
End Sub



Private Sub Form_Load()
frmPrincipal.Width = "8900"
'defien width of the window to 8900

cmdSend.Enabled = False
'Disable the send Button

cmdVidClose.Visible = False
'Hide the Video Close Button

'cmdDisconnect.Visible = False
'hide the Disconnect Button


End Sub

Private Sub txtTempString_Change()
If txtTempString.Text = "" Then
    cmdSend.Enabled = False
Else
    cmdSend.Enabled = True
End If
End Sub

[U][B]SERVER SIDE[/B][/U]

Private Sub cmdStartListening_Click()

On Error GoTo error_handle_for_listening
' In case there is any error, this will jump to the
' "error_handle_for_listening" section

Winsock1.Close
' We close it in case its listening before

Winsock1.LocalPort = txtPortno.Text
' Local port of the winsock control is the text value entered in "txtPortno"

Winsock1.Listen
'Start listening

Exit Sub

error_handle_for_listening:
'Block for error handeling

MsgBox "Error : " & Err.Description, vbCritical
'This will display the error generated by the winsock control.

End Sub

Private Sub cmdSend_Click()
On Error GoTo error_handle_for_SendingData

Winsock1.SendData txtTempString.Text
'Transmits the string of text to the host (Client)

rtbMainConsole.Text = rtbMainConsole.Text & "Server : " & txtTempString.Text & vbCrLf
'This displays the same sent string on the Main chat Console

txtTempString.Text = ""
'Clears the textbox for the next entry of the string (Message)

txtTempString.SetFocus
'Sets the focus back to the "txtTempString" to enter next string

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

Exit Sub
error_handle_for_SendingData:
'Block for error handeling

MsgBox "Error : " & Err.Description, vbCritical
'This will display the error generated by the winsock control.

Winsock1_Close
'We will close the winsock connection i case their is any error

End Sub

Private Sub Winsock1_Close()

Winsock1.Close
'Closes the winsock connection


rtbMainConsole.Text = rtbMainConsole.Text & " *** Disconnected " & vbCrLf
'Display the disconnected error

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
'This function is used to handle the connection initiation be the client
'This event is triggered when a client try to connect on our host
'We must accept the request for the connection to be completed

If Winsock1.State <> sckClosed Then Winsock1.Close
'Check if the state of the winsock connection
'If the state is closed, then the Connection is closed

Winsock1.Accept requestID
'With this we can accept the connection from the clients &
'then start sending / receiving the Data

rtbMainConsole.Text = " Client Connected. IP = " & Winsock1.RemoteHostIP & vbCrLf
'Display the Client connected & its IP address

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'This is being trigger every time new data arrive from the client

Dim strData As String
'The incomming data is received & saved in this variable

Winsock1.GetData strData, vbString
'The wisock connection is received here

rtbMainConsole.Text = rtbMainConsole.Text & "Client : " & strData & vbCrLf
'Displays the received data in the main chat console

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

End Sub

Private Sub sock1_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)
'This event is to handle any kind of errors happend while using winsock

'Number gives you the number code of that specific error
'Description gives you string with a simple explanation about the error

rtbMainConsole.Text = rtbMainConsole.Text & "*** Error : " & Description & vbCrLf
'Displays the received data in the main chat console

rtbMainConsole.SelStart = Len(rtbMainConsole)
'This is used to autoscroll down the Main Chat Console

'and now we need to close the connection
Winsock1_Close

End Sub

Private Sub Form_Load()
cmdSend.Enabled = False
End Sub

Private Sub txtTempString_Change()
If txtTempString.Text = "" Then
    cmdSend.Enabled = False
Else
    cmdSend.Enabled = True
End If
End Sub

Some of this is Extra shit load added for crappy fun....the rest is winsock prog...plz help in creating a many to many chat portal using these mere components

put it in code tags in future

And what's our incentive to read 320 lines which inlcudes "Extra shit load added for crappy fun"? Maybe you should post the section you are having trouble with...

I am sorry for not putting it into code tags...my bad....and also de crappy stuff is jus some mere lines for personalised Interface actions....in this code i have made a one to one chat using a server and client side...where in i can only chat with one client on one port...i need help converting it into a program wherein i can chat with many ppl in the same window..i.e conference...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.