Client-Server application
-
But is there a different between a chatting application and a sending of data application? Because what i looking for is send of data.
-
-
-
Sorry to disturb again.. For the link u pass me.. Is it possible for the server to reply to the client? Because for the current project it is not possible.
-
But there isn't any code inside the server that allow reply right? So can u advise where can i go and find the reply source code and construct a delegate?
I don't understand what you mean, "that allow reply". The server code has events inside it to notify the clients of new messages, and to update their view. Everything should be inside there and you're not going to get any much better as an example then that.
-
I don't understand what you mean, "that allow reply". The server code has events inside it to notify the clients of new messages, and to update their view. Everything should be inside there and you're not going to get any much better as an example then that.
Ya i know what u mean. Create a delegate and when a event is raise run the delegate right? But for the server part i didnt notice any code which allows reply. Can u tell me which part of the code do a reply? They do not have any stream.write on the server side..
-
Ya i know what u mean. Create a delegate and when a event is raise run the delegate right? But for the server part i didnt notice any code which allows reply. Can u tell me which part of the code do a reply? They do not have any stream.write on the server side..
Dude, did you even READ[^] the bloody website? It says, and I quote
http://vb.net-informations.com/communications/vb.net\_chat\_server.htm wrote:
When a Chat Client connected to Server , the Server create a new Thread for communication . Here we implement a Class handleClient for handling Client as a separate Thread . The Class handleClient has a function doChat() is handling the communication between the Server side Client Socket and the incoming Client Socket.
READ it and analyze the code better. Look at the broadcast method to see how it sends a message to users that a new connection has been established. If you can't figure it out with all that's layed out in front of you then you won't be able to do it at all.
-
Dude, did you even READ[^] the bloody website? It says, and I quote
http://vb.net-informations.com/communications/vb.net\_chat\_server.htm wrote:
When a Chat Client connected to Server , the Server create a new Thread for communication . Here we implement a Class handleClient for handling Client as a separate Thread . The Class handleClient has a function doChat() is handling the communication between the Server side Client Socket and the incoming Client Socket.
READ it and analyze the code better. Look at the broadcast method to see how it sends a message to users that a new connection has been established. If you can't figure it out with all that's layed out in front of you then you won't be able to do it at all.
I already edited on the code i have and the server do reply to its client but somehow the reply was not the expect result. Somehow the 1st request and reply are correct but the 2nd request and reply onward the application skip the 1st 2 letter of wat i type. I dont understand which part have i gone wrong. I have posted my code, pls advise on my mistake. Thanks a lot. Private Sub doChat() Dim infiniteCounter As Integer Dim requestCount As Integer Dim bytesFrom(10024) As Byte Dim dataFromClient, DataToClient As String Dim sendBytes As [Byte]() Dim serverResponse As String Dim rCount As String requestCount = 0 For infiniteCounter = 1 To 2 infiniteCounter = 1 Try requestCount = requestCount + 1 Dim networkStream As NetworkStream = _ clientSocket.GetStream() networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize)) dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom) dataFromClient = _ dataFromClient.Substring(0, dataFromClient.IndexOf("$")) msg("From client - " + clNo + " : " + dataFromClient) rCount = Convert.ToString(requestCount) serverResponse = "ok" sendBytes = System.Text.Encoding.ASCII.GetBytes(serverResponse) networkStream.Write(bytesFrom, 0, serverResponse.Length) msg("From Server - " + serverResponse) DataToClient = networkStream.Read(sendBytes, 0, sendBytes.Length) broadcast(dataFromClient, clNo, True) broadcast(serverResponse, "Server", True) Catch ex As Exception MsgBox(ex.ToString) End Try Next End Sub
-
I already edited on the code i have and the server do reply to its client but somehow the reply was not the expect result. Somehow the 1st request and reply are correct but the 2nd request and reply onward the application skip the 1st 2 letter of wat i type. I dont understand which part have i gone wrong. I have posted my code, pls advise on my mistake. Thanks a lot. Private Sub doChat() Dim infiniteCounter As Integer Dim requestCount As Integer Dim bytesFrom(10024) As Byte Dim dataFromClient, DataToClient As String Dim sendBytes As [Byte]() Dim serverResponse As String Dim rCount As String requestCount = 0 For infiniteCounter = 1 To 2 infiniteCounter = 1 Try requestCount = requestCount + 1 Dim networkStream As NetworkStream = _ clientSocket.GetStream() networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize)) dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom) dataFromClient = _ dataFromClient.Substring(0, dataFromClient.IndexOf("$")) msg("From client - " + clNo + " : " + dataFromClient) rCount = Convert.ToString(requestCount) serverResponse = "ok" sendBytes = System.Text.Encoding.ASCII.GetBytes(serverResponse) networkStream.Write(bytesFrom, 0, serverResponse.Length) msg("From Server - " + serverResponse) DataToClient = networkStream.Read(sendBytes, 0, sendBytes.Length) broadcast(dataFromClient, clNo, True) broadcast(serverResponse, "Server", True) Catch ex As Exception MsgBox(ex.ToString) End Try Next End Sub