please help me,.,.i really don't know how to use winsock,,.,.my group and i were assigned to create a chat program using winsock,.,.,.,,,whether it is simple or not,but the simpler the better.,.,.please help me.....i don't know how to start,i don't even understand how to use winsock in visual basic?!!!!!!!
how to create a simple chat using winsock in visual basic???
winsock is very very simple.
firstly load the winsock control (goto add components and its called "microsoft winsock control 6.0")
then on your form create 3 text boxes. label them as such: txtRemoteIP, txtMain, txtMessage
txtmain should have these settings:
MultiLine should be set to true
scrollbars should be set to vertical
enabled should be set to false
then create 2 buttons and call them cmdSend and cmdConnect
then put a winsock control in and call it sckMain
then open up the code and put in this
there may be some errors in it but that was a rough chat program i made up in the last 10 mins for you.
however looking at the date of your post i relise this may be of no use to you. well anyway feel free to edit this code as you want and if anybody can see any errors please tell me so i can correct them.
firstly load the winsock control (goto add components and its called "microsoft winsock control 6.0")
then on your form create 3 text boxes. label them as such: txtRemoteIP, txtMain, txtMessage
txtmain should have these settings:
MultiLine should be set to true
scrollbars should be set to vertical
enabled should be set to false
then create 2 buttons and call them cmdSend and cmdConnect
then put a winsock control in and call it sckMain
then open up the code and put in this
| Code: |
| Private Sub cmdConnect_Click()
With sckMain .RemoteHost = txtRemoteIP.Text .RemotePort = "6677" .Connect End With End Sub Private Sub cmdSend_Click() If sckMain.State = sckClosed Then: Exit Sub sckMain.SendData txtMessage.Text End Sub Private Sub Form_Load() sckMain.LocalPort = "6677" sckMain.Listen End Sub Private Sub sckMain_Close() txtMain.Text = txtMain.Text & vbCrLf & "<Session Ended>" sckMain.LocalPort = "6677" sckMain.Listen End Sub Private Sub sckMain_Connect() txtMain.Text = txtMain.Text & vbCrLf & "<Connected with: " & sckMain.RemoteHostIP & ">" End Sub Private Sub sckMain_ConnectionRequest(ByVal requestID As Long) If MsgBox("would you like to connect with " & sckMain.RemoteHostIP & "?", vbYesNo) = vbYes Then ' you must close the socket before you can accept it sckMain.Close sckMain.Accept requestID End If End Sub Private Sub sckMain_DataArrival(ByVal bytesTotal As Long) Dim buffer As String sckMain.GetData (buffer) MsgBox buffer txtMain.Text = txtMain.Text & vbCrLf & "Them: " & buffer End Sub Private Sub sckMain_SendComplete() txtMain.Text = txtMain.Text & vbCrLf & "You: " & txtMessage.Text txtMessage.Text = "" End Sub |
there may be some errors in it but that was a rough chat program i made up in the last 10 mins for you.
however looking at the date of your post i relise this may be of no use to you. well anyway feel free to edit this code as you want and if anybody can see any errors please tell me so i can correct them.
Thank you for your help. 
