11-08-2010, 03:20 AM
Here is a simple chat program that uses IP's to talk to each other.
You can adapt it to work how you like;
You can adapt it to work how you like;
Code:
Imports VB = Microsoft.VisualBasic
Public Class frmChat
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer
Dim UserID As String
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Private Sub btnMySend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMySend.Click
Dim Message As String
Message = "[" & UserID & "] " & txtMySend.Text
AxWinsock1.RemoteHost = AxWinsock1.LocalIP
AxWinsock1.SendData(Of Date)()
If AxWinsock1.LocalIP = txtIPAddress.Text Then
AxWinsock1.RemoteHost = txtIPAddress.Text
AxWinsock1.SendData(Message)
End If
txtMySend.Text = ""
txtMySend.Focus()
End Sub
Private Sub frmChat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxWinsock1.Protocol = MSWinsockLib.ProtocolConstants.sckTCPProtocol
AxWinsock1.RemoteHost = AxWinsock1.LocalIP
AxWinsock1.RemotePort = 10
AxWinsock1.LocalPort = 11
Dim sBuffer As String
Dim lSize As Integer
sBuffer = Space(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
UserID = VB.Left(sBuffer, lSize - 1)
Else
UserID = vbNullString
End If
Me.Text = Me.Text + UserID & " at " & AxWinsock1.LocalIP
txtIPAddress.Text = AxWinsock1.LocalIP
txtMyIP.Text = AxWinsock1.LocalIP
End Sub
Private Sub AxWinsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles AxWinsock1.DataArrival
Dim Arrival As String = ""
AxWinsock1.GetData(Arrival)
txtMyArrival.Text = txtMyArrival.Text & Arrival & vbNewLine
End Sub
Private Sub txtIPAddress_Leave(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles txtIPAddress.Leave
AxWinsock1.RemoteHost = txtIPAddress.Text
End Sub
End Class
Someone with no history is nothing but suspicious.