PDA

View Full Version : VB.Net assembly to send event through TCPIP... what's wrong?



jeffaries
December 20th, 2004, 03:20 PM
Here is a class in vb.net that I am creating to send event to internet event server.
It send the "quintessence\n"... receive the cookie...
I think I encrypt well the <cookie>:<password>.... but... when I send it ... I only receive a new cookie... no "accept\n"..

Any Idea ?

Thank you for any help

Jeff

----------------------------------------------------

Imports System.Net
Imports System.Timers
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Imports Microsoft.VisualBasic
Imports System.Security.Cryptography

Public Class GirderEventClient

Private Sub sendMessage(message as string)
Dim ipPort as integer = 1024
Dim host as string = "192.168.3.2"
Dim socClient As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim socClient2 As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim ipHostInfo As IPHostEntry = Dns.Resolve(host)
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
Dim remoteEP As New IPEndPoint(ipAddress, ipPort)
socClient.Connect(remoteEP)


Dim msg As Byte() = Encoding.ASCII.GetBytes("quintessence" & vbLf)
Dim bytesSent As Integer = socClient.Send(msg)
Dim bytes(1024) As Byte
Dim bytesRec As Integer = socClient.Receive(bytes)
Dim cookie As String = Replace(Encoding.ASCII.GetString(bytes, 0, bytesRec), vbLf, "")
If cookie <> "" Then
cookie = cookie.Substring(0, 4)
Label1.Text = cookie
Dim strPlainText As String = cookie & ":password"
Dim hashedDataBytes() As Byte
Dim encoder As New ASCIIEncoding
Dim md5Hasher As New MD5CryptoServiceProvider
Dim sb As New StringBuilder
hashedDataBytes = md5Hasher.ComputeHash(encoder.GetBytes(strPlainTex t))
'For Each b As Byte In hashedDataBytes
' sb.Append(b.ToString("x2"))
'Next
'sb.Append(vbLf)
'strPlainText = sb.ToString
bytesSent = socClient.Send(encoder.GetBytes(strPlainText))
bytesRec = socClient.Receive(bytes)
Label1.Text = Encoding.ASCII.GetString(bytes, 0, 1024)
msg = Encoding.ASCII.GetBytes("TEST" & vbLf)
bytesSent = socClient.Send(msg)
End If
socClient.Close()


End Sub
End Class

Promixis
December 20th, 2004, 06:36 PM
I believe Jim Hughs has already written code to do this...
http://www.hughestechnology.com/20/Default.aspx?tabid=26