Click here to Skip to main content
15,667,864 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I am working on a college project . The project is network Banking system. I have designed two programs, one for server(admin) and one for the client(customers). The connection is via TCP sockets. here is a brief description:

When the customer(client) logs in by providing the account number and password correctly, the networkstream object transmits account number properly but this is not the case with passwords. When I extract the password on the server side it is not a valid string to fit into the Sql query for verifying the user details in the database. The password String looks like "abc with a missing closing double quotes. The buffer size is 10025.

Here is the server code:

Public Sub Client_Login()

       networkStream = clientSocket.GetStream()
       Dim bytes(10024) As Byte
       networkStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))
       ClientID = (Encoding.ASCII.GetString(bytes))

       networkStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))
       ClientPassword = (Encoding.ASCII.GetString(bytes))

       connection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source= D:\Project(Pritam)\Networking Banking System\ActualDatabase.mdb")
       SQL = "Select * from ClientInfo  where Account_No= " & ClientID & "  and  [Password]='" & ClientPassword & "'"
       command = New OleDbCommand(SQL, connection)
       reader = command.ExecuteReader()

       If reader.HasRows = True Then
           Dim ClientAccountNumber As Integer = reader("Account_No")  'extracts account number from database
           Dim PasswordClient As String = reader("Password")        ' extracts password from database

           If ClientAccountNumber = Val(ClientID) And PasswordClient = (ClientPassword) Then

               server_response = "Successful Login"
               Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(server_response)
               networkStream.Write(sendBytes, 0, sendBytes.Length)

Here is the client code:
Private Sub cmdSignin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSignin.Click

       If txtClientID.Text <> "" And txtClientPassword.Text <> "" Then


               networkStream = clientSocket.GetStream()
               Dim to_server As Byte() = Encoding.ASCII.GetBytes(txtClientID.Text)
               networkStream.Write(to_server, 0, to_server.Length)

               'Dim client_writer As New StreamWriter(clientSocket.GetStream())

               to_server = Encoding.ASCII.GetBytes(txtClientPassword.Text)
               networkStream.Write(to_server, 0, to_server.Length)


               Dim login_Thread As Threading.Thread = New Threading.Thread(AddressOf login_final)

           Catch ex As Exception
               MsgBox("Server not found" & vbCrLf & "Contact Administrator", MsgBoxStyle.Critical, "Notice!!")
           End Try

Kindly help me as I've to submit my project very soon, please.

Thanking you in advance

--EDIT kschuler: tried to fix code blocks, bolded the actual question to make it stand out more.
Updated 9-Mar-11 20:14pm

1 solution

This is due to your buffer being a fixed size. Make it dynamic and it should work fine.

Dim bytes() As Byte
Redim bytes(CInt(clientSocket.ReceiveBufferSize)-1)
networkStream.Read(bytes, 0, CInt(clientSocket.ReceiveBufferSize))

To be fair, I am quite surprised that your two sets of data didn't get merged into a single network packet. That used to happen in VB6, maybe .NET handles packets slightly different
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900