Rabu, 27 Februari 2013

Program Chatting dengan VB 6.0



      Program Chatting ini saya dapat dari dosen saya di perkulihan. untuk melihatnya silahkan download programnya  disini.



Jika anda ingin membuat programnya sendiri. berikut ini listing programnya :
  Server :

Option Explicit
Private Sub cmdSend_Click()
    Winsock1.SendData txtChat.Text
    DoEvents
   
    txtMain.Text = txtMain.Text & vbCrLf & txtChat.Text
    txtChat.Text = ""
End Sub

Private Sub Form_Load()
    Winsock1.LocalPort = 11111
    Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    'reset the socket, and accept the new connection
    Winsock1.Close
    Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String

    'get the data and display it in the textbox
    Winsock1.GetData strData
    txtMain.Text = txtMain.Text & vbCrLf & strData
    txtMain.SelStart = Len(txtMain.Text)
End Sub

Kien :
Option Explicit

Private Sub Form_Load()
    'set up the Winsock1 to connect to the local computer
    Winsock1.RemoteHost = "127.0.0.1"
    Winsock1.RemotePort = 11111
    Winsock1.Connect
End Sub

Private Sub cmdSend_Click()
    'send the data thats in the text box and
    'clear it to prepare for the next chat message
    Winsock1.SendData txtChat.Text
    DoEvents
   
    txtMain.Text = txtMain.Text & vbCrLf & txtChat.Text
    txtChat.Text = ""
End Sub

Private Sub Winsock1_Connect()
    'we are connected!
    MsgBox "Connected"
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
   
    ' get the data from the socket
    Winsock1.GetData strData
    ' display it in the textbox
    txtMain.Text = txtMain.Text & vbCrLf & strData
    ' scroll the box down
    txtMain.SelStart = Len(txtMain.Text)
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)
    ' an error has occured somewhere, so let the user know
    MsgBox "Error: " & Description
    ' close the socket, ready to go again
    Winsock1.Close
End Sub

Akhir kata Semoga bermanfaat..........



Tidak ada komentar:

Posting Komentar