Please see my comment to the question. Your complain "but client is not accessible…" is absurd. You need to remember that you are the one who define what is acceptable where. For example, your
client
could be the instance member (most typically, a private member) of the same class and the declaring class of the instance method
WriteToEth
; then this method can access
client
.
Initialization of
client
could be done using the
lazy pattern, that is, only when you use it for the very first time, or be done at the very beginning of the lifetime of its declaring class, say, in its constructor. See also:
https://en.wikipedia.org/wiki/Lazy_initialization[
^],
https://msdn.microsoft.com/en-us/library/dd642331%28v=vs.110%29.aspx[
^] (you don't need to use this class, it's only for your convenience).
Besides, if you develop some UI, all the network communications using the TCP client (or anything else) should rather be done in a separate thread, so you also need to learn threading and communication between threads and the UI thread.
And so on… You should not take my suggestions as some solution. Rather, this is the illustration of the idea that a software development should really design the code, freely combining different aspects of all the repertoire of different options and expressive capabilities of the platform and the languages. Such "problems" as the one you complain about should not be considered as problems; it should be all on the tips of your finger. (There are real problem, a lot of them.) How to achieve that? Learning of theory and practice, and, importantly, sharpening your skills on much simpler projects, which could be purely study projects at first.
—SA