I am using Asynchronous Server Socket Example
There is another post which is exactly what I am experiencing, but can't find proper solution: Stackoverflow post
I need to pass additional information, strings from StartListening() function all the way to ReadCallback function. So If I am correct, additional information (strings) should go from StartListening to AcceptCallback and then from AcceptCallback to ReadCallback so in ReadCallback I can finally use passed strings.
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener)
and
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
already have parameters assigned (listener and state) which doesn't allow me to pass more parameters.
I think List can be used to pass multiple objects and strings, but how exactly it should be done to pass and, later use required data.
I tried to create List:
var listenerObject = new List<object>();
listenerObject.Add(new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp));
listenerObject.Add(AdditionalParameter);
How to make it work to pass data to AcceptCallback and ReadCallback functions?