BrandonPotter / SimpleTCP

Straightforward .NET library to handle the repetitive tasks of spinning up and working with TCP sockets (client and server).
Apache License 2.0
368 stars 108 forks source link

SimpleTcpClient.WriteAndGetReply? #41

Open rualmar opened 6 years ago

rualmar commented 6 years ago

I've been using this framework for a while for simple TCP communications (thanks a lot for making our life easy), but I've reached a point where I need to send a message and listen for the reply synchronously. I've tested with SimpleTcpClient method WriteLineAndGetReply but the problem is that this method inserts a trailing line end char at the end of the string I'm sending, and the thid party system which I'm sending messages to does not support it. Is there any way to remove the final char? Something like WriteAndGetReply?

Thanks.

Edit: (early sending) I've been testing the implementation by copying the code for the method WriteLineAndGetReply and replacing the WriteLine(data) with Write(data). If you see it interesting I may fork the repository and send a pull request with the method WriteAndGetReply.

michaelgaultjr commented 6 years ago

I'd love to see this feature, I'm currently working on a project where this would be extremely useful

matt1tk commented 4 years ago

All messages received have "‼" (a double exclamation point in a single character) added on to the end of it. Is this the same issue you're referring to?

matt1tk commented 4 years ago

If so, use

message.MessageString.Remove(message.MessageString.Length-1, 1)

not

message.MessageString

GnRSlash commented 2 years ago

This part of your code will not work: if (data.LastOrDefault() != Delimiter) { Write(data + StringEncoder.GetString(new byte[] { Delimiter })); }

And this: delimiter = 0x13; <---- is wrong, the right way is: delimiter = 0x0D; or just delimiter = 13; Because you are comparing LastOrDefault (which is a char), with a delimiter (which is a byte), and you are always adding a delimiter to the end