TCP Client-Side Not Recieveing Data Properly VB.NET
I'm trying to make a simple client-side application to recieve small text data, compare it and then does something on client machine depending on what server sent.
Server Logic: The server side is made in java, so can't change anything there. Server sends string "abc001" on connecting to client.
Client Logic: Client recieves the string "abc001" from server & checks if it's recieved string is the same as "abc001", then does something accordingly.
Problem: When the client recieves data, I display it in msgbox. But instead of just "abc001", there pops up an extra blank msgbox(image included).
Client Code - On Start:
Try
' declare vals
Dim ip As String = "127.0.0.1"
Dim port As Integer = 5000
' set client
_client = New TcpClient(ip, port)
' disable cross thread calls checking
CheckForIllegalCrossThreadCalls = False
' recieve msg
Threading.ThreadPool.QueueUserWorkItem(AddressOf RecieveMessages)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Client Code - Recieve Data
Private Sub RecieveMessages(state As Object)
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
MsgBox(txt)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
MsgBox 1
MsgBox 2
How to not get the blank msgbox. Even when compared, the data recived does not match parameters. Tried to use delay, tried fixing the buffer size to 6 bytes but no use.. Any help is appreciated. Thanks.
EDIT 1: Tried my best to figure it out but can't.. Tried cleaning the returned string data and even tried storing each return data in array. Saw the stack and it says the msgbox has "nothing" in it. It's null.. I don't even know what to do.. Here's the code for strings clean:
Private Sub RecieveMessages(state As Object)
Dim message(0) As String
Dim command_raw, command_clean, command As String
Dim counter As Integer = 0
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
message(0) = txt
command_raw = message(0)
command_clean = command_raw.Replace(vbCrLf, Nothing)
command = command_clean.Substring(0, 6)
MsgBox(command)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
vb.net sockets client-server tcpclient
|
show 3 more comments
I'm trying to make a simple client-side application to recieve small text data, compare it and then does something on client machine depending on what server sent.
Server Logic: The server side is made in java, so can't change anything there. Server sends string "abc001" on connecting to client.
Client Logic: Client recieves the string "abc001" from server & checks if it's recieved string is the same as "abc001", then does something accordingly.
Problem: When the client recieves data, I display it in msgbox. But instead of just "abc001", there pops up an extra blank msgbox(image included).
Client Code - On Start:
Try
' declare vals
Dim ip As String = "127.0.0.1"
Dim port As Integer = 5000
' set client
_client = New TcpClient(ip, port)
' disable cross thread calls checking
CheckForIllegalCrossThreadCalls = False
' recieve msg
Threading.ThreadPool.QueueUserWorkItem(AddressOf RecieveMessages)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Client Code - Recieve Data
Private Sub RecieveMessages(state As Object)
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
MsgBox(txt)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
MsgBox 1
MsgBox 2
How to not get the blank msgbox. Even when compared, the data recived does not match parameters. Tried to use delay, tried fixing the buffer size to 6 bytes but no use.. Any help is appreciated. Thanks.
EDIT 1: Tried my best to figure it out but can't.. Tried cleaning the returned string data and even tried storing each return data in array. Saw the stack and it says the msgbox has "nothing" in it. It's null.. I don't even know what to do.. Here's the code for strings clean:
Private Sub RecieveMessages(state As Object)
Dim message(0) As String
Dim command_raw, command_clean, command As String
Dim counter As Integer = 0
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
message(0) = txt
command_raw = message(0)
command_clean = command_raw.Replace(vbCrLf, Nothing)
command = command_clean.Substring(0, 6)
MsgBox(command)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
vb.net sockets client-server tcpclient
Port is 5000 or 58818? Are you sure the server sends abc001 and not cmd001 as it seems?
– Alessandro Mandelli
Nov 19 '18 at 16:06
abc001 is example. 6 bytes data is sent. When reading the data, there is something extra or something wrong with code. The port is same in both server and client, because set from txtbox. There should be only 1 msgbox open when 1 thing is sent.. but 2 open
– SimpleCoder
Nov 19 '18 at 21:04
1
This right here is the first indication that you're doing something very wrong:CheckForIllegalCrossThreadCalls = False
- NEVER change this toFalse
! It's an important check that stops you from doing bad things that breaks your application completely! Do it right from the beginning instead so that you don't have to change anything later. See my answer at How can I run code in a background thread and still access the UI? for how you can access the UI in a thread-safe manner.
– Visual Vincent
Nov 20 '18 at 6:31
It's probably just an extra cr+lf
– Alessandro Mandelli
Nov 20 '18 at 7:17
Thanks @VisualVincent Will try implementing safe way.
– SimpleCoder
Nov 20 '18 at 13:01
|
show 3 more comments
I'm trying to make a simple client-side application to recieve small text data, compare it and then does something on client machine depending on what server sent.
Server Logic: The server side is made in java, so can't change anything there. Server sends string "abc001" on connecting to client.
Client Logic: Client recieves the string "abc001" from server & checks if it's recieved string is the same as "abc001", then does something accordingly.
Problem: When the client recieves data, I display it in msgbox. But instead of just "abc001", there pops up an extra blank msgbox(image included).
Client Code - On Start:
Try
' declare vals
Dim ip As String = "127.0.0.1"
Dim port As Integer = 5000
' set client
_client = New TcpClient(ip, port)
' disable cross thread calls checking
CheckForIllegalCrossThreadCalls = False
' recieve msg
Threading.ThreadPool.QueueUserWorkItem(AddressOf RecieveMessages)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Client Code - Recieve Data
Private Sub RecieveMessages(state As Object)
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
MsgBox(txt)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
MsgBox 1
MsgBox 2
How to not get the blank msgbox. Even when compared, the data recived does not match parameters. Tried to use delay, tried fixing the buffer size to 6 bytes but no use.. Any help is appreciated. Thanks.
EDIT 1: Tried my best to figure it out but can't.. Tried cleaning the returned string data and even tried storing each return data in array. Saw the stack and it says the msgbox has "nothing" in it. It's null.. I don't even know what to do.. Here's the code for strings clean:
Private Sub RecieveMessages(state As Object)
Dim message(0) As String
Dim command_raw, command_clean, command As String
Dim counter As Integer = 0
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
message(0) = txt
command_raw = message(0)
command_clean = command_raw.Replace(vbCrLf, Nothing)
command = command_clean.Substring(0, 6)
MsgBox(command)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
vb.net sockets client-server tcpclient
I'm trying to make a simple client-side application to recieve small text data, compare it and then does something on client machine depending on what server sent.
Server Logic: The server side is made in java, so can't change anything there. Server sends string "abc001" on connecting to client.
Client Logic: Client recieves the string "abc001" from server & checks if it's recieved string is the same as "abc001", then does something accordingly.
Problem: When the client recieves data, I display it in msgbox. But instead of just "abc001", there pops up an extra blank msgbox(image included).
Client Code - On Start:
Try
' declare vals
Dim ip As String = "127.0.0.1"
Dim port As Integer = 5000
' set client
_client = New TcpClient(ip, port)
' disable cross thread calls checking
CheckForIllegalCrossThreadCalls = False
' recieve msg
Threading.ThreadPool.QueueUserWorkItem(AddressOf RecieveMessages)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Client Code - Recieve Data
Private Sub RecieveMessages(state As Object)
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
MsgBox(txt)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
MsgBox 1
MsgBox 2
How to not get the blank msgbox. Even when compared, the data recived does not match parameters. Tried to use delay, tried fixing the buffer size to 6 bytes but no use.. Any help is appreciated. Thanks.
EDIT 1: Tried my best to figure it out but can't.. Tried cleaning the returned string data and even tried storing each return data in array. Saw the stack and it says the msgbox has "nothing" in it. It's null.. I don't even know what to do.. Here's the code for strings clean:
Private Sub RecieveMessages(state As Object)
Dim message(0) As String
Dim command_raw, command_clean, command As String
Dim counter As Integer = 0
Try
While True
Dim ns As NetworkStream = _client.GetStream()
Dim toRecieve(_client.ReceiveBufferSize) As Byte
ns.Read(toRecieve, 0, CInt(_client.ReceiveBufferSize))
Dim txt As String = Encoding.ASCII.GetString(toRecieve)
message(0) = txt
command_raw = message(0)
command_clean = command_raw.Replace(vbCrLf, Nothing)
command = command_clean.Substring(0, 6)
MsgBox(command)
End While
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
vb.net sockets client-server tcpclient
vb.net sockets client-server tcpclient
edited Nov 20 '18 at 13:22
asked Nov 19 '18 at 15:53


SimpleCoder
376
376
Port is 5000 or 58818? Are you sure the server sends abc001 and not cmd001 as it seems?
– Alessandro Mandelli
Nov 19 '18 at 16:06
abc001 is example. 6 bytes data is sent. When reading the data, there is something extra or something wrong with code. The port is same in both server and client, because set from txtbox. There should be only 1 msgbox open when 1 thing is sent.. but 2 open
– SimpleCoder
Nov 19 '18 at 21:04
1
This right here is the first indication that you're doing something very wrong:CheckForIllegalCrossThreadCalls = False
- NEVER change this toFalse
! It's an important check that stops you from doing bad things that breaks your application completely! Do it right from the beginning instead so that you don't have to change anything later. See my answer at How can I run code in a background thread and still access the UI? for how you can access the UI in a thread-safe manner.
– Visual Vincent
Nov 20 '18 at 6:31
It's probably just an extra cr+lf
– Alessandro Mandelli
Nov 20 '18 at 7:17
Thanks @VisualVincent Will try implementing safe way.
– SimpleCoder
Nov 20 '18 at 13:01
|
show 3 more comments
Port is 5000 or 58818? Are you sure the server sends abc001 and not cmd001 as it seems?
– Alessandro Mandelli
Nov 19 '18 at 16:06
abc001 is example. 6 bytes data is sent. When reading the data, there is something extra or something wrong with code. The port is same in both server and client, because set from txtbox. There should be only 1 msgbox open when 1 thing is sent.. but 2 open
– SimpleCoder
Nov 19 '18 at 21:04
1
This right here is the first indication that you're doing something very wrong:CheckForIllegalCrossThreadCalls = False
- NEVER change this toFalse
! It's an important check that stops you from doing bad things that breaks your application completely! Do it right from the beginning instead so that you don't have to change anything later. See my answer at How can I run code in a background thread and still access the UI? for how you can access the UI in a thread-safe manner.
– Visual Vincent
Nov 20 '18 at 6:31
It's probably just an extra cr+lf
– Alessandro Mandelli
Nov 20 '18 at 7:17
Thanks @VisualVincent Will try implementing safe way.
– SimpleCoder
Nov 20 '18 at 13:01
Port is 5000 or 58818? Are you sure the server sends abc001 and not cmd001 as it seems?
– Alessandro Mandelli
Nov 19 '18 at 16:06
Port is 5000 or 58818? Are you sure the server sends abc001 and not cmd001 as it seems?
– Alessandro Mandelli
Nov 19 '18 at 16:06
abc001 is example. 6 bytes data is sent. When reading the data, there is something extra or something wrong with code. The port is same in both server and client, because set from txtbox. There should be only 1 msgbox open when 1 thing is sent.. but 2 open
– SimpleCoder
Nov 19 '18 at 21:04
abc001 is example. 6 bytes data is sent. When reading the data, there is something extra or something wrong with code. The port is same in both server and client, because set from txtbox. There should be only 1 msgbox open when 1 thing is sent.. but 2 open
– SimpleCoder
Nov 19 '18 at 21:04
1
1
This right here is the first indication that you're doing something very wrong:
CheckForIllegalCrossThreadCalls = False
- NEVER change this to False
! It's an important check that stops you from doing bad things that breaks your application completely! Do it right from the beginning instead so that you don't have to change anything later. See my answer at How can I run code in a background thread and still access the UI? for how you can access the UI in a thread-safe manner.– Visual Vincent
Nov 20 '18 at 6:31
This right here is the first indication that you're doing something very wrong:
CheckForIllegalCrossThreadCalls = False
- NEVER change this to False
! It's an important check that stops you from doing bad things that breaks your application completely! Do it right from the beginning instead so that you don't have to change anything later. See my answer at How can I run code in a background thread and still access the UI? for how you can access the UI in a thread-safe manner.– Visual Vincent
Nov 20 '18 at 6:31
It's probably just an extra cr+lf
– Alessandro Mandelli
Nov 20 '18 at 7:17
It's probably just an extra cr+lf
– Alessandro Mandelli
Nov 20 '18 at 7:17
Thanks @VisualVincent Will try implementing safe way.
– SimpleCoder
Nov 20 '18 at 13:01
Thanks @VisualVincent Will try implementing safe way.
– SimpleCoder
Nov 20 '18 at 13:01
|
show 3 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378292%2ftcp-client-side-not-recieveing-data-properly-vb-net%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378292%2ftcp-client-side-not-recieveing-data-properly-vb-net%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Port is 5000 or 58818? Are you sure the server sends abc001 and not cmd001 as it seems?
– Alessandro Mandelli
Nov 19 '18 at 16:06
abc001 is example. 6 bytes data is sent. When reading the data, there is something extra or something wrong with code. The port is same in both server and client, because set from txtbox. There should be only 1 msgbox open when 1 thing is sent.. but 2 open
– SimpleCoder
Nov 19 '18 at 21:04
1
This right here is the first indication that you're doing something very wrong:
CheckForIllegalCrossThreadCalls = False
- NEVER change this toFalse
! It's an important check that stops you from doing bad things that breaks your application completely! Do it right from the beginning instead so that you don't have to change anything later. See my answer at How can I run code in a background thread and still access the UI? for how you can access the UI in a thread-safe manner.– Visual Vincent
Nov 20 '18 at 6:31
It's probably just an extra cr+lf
– Alessandro Mandelli
Nov 20 '18 at 7:17
Thanks @VisualVincent Will try implementing safe way.
– SimpleCoder
Nov 20 '18 at 13:01