/// <summary> /// The socket state constructor that initializes what socket, id, and delegate /// will be passed around in the Network Controller and Game Controller. /// </summary> /// <param name="s"></param> /// <param name="_id"></param> /// <param name="callMeParameter"></param> public SocketState(Socket s, int _id, callMeDelegate callMeParameter) { theSocket = s; id = _id; callMe = callMeParameter; sb = new StringBuilder(); messageBuffer = new byte[1024]; }
public static void ServerAwaitingClientLoop(callMeDelegate callMe) { TcpListener listener = new TcpListener(IPAddress.Any, DEFAULT_PORT); listener.Start(); ConnectionState cState = new ConnectionState(callMe, listener); listener.BeginAcceptSocket(AcceptNewClient, cState); }
/// <summary> /// Attempts to connect to the server via a provided hostname. /// Saves the callMe function in a socket state object for use when data arrives. /// </summary> /// <param name="callMe"></param> /// <param name="hostname"></param> /// <returns></returns> public static Socket ConnectToServer(callMeDelegate callMe, string hostname) { IPAddress ipAddress; Socket socket; MakeSocket(hostname, out socket, out ipAddress); SocketState ss = new SocketState(socket, -1, callMe); ss.theSocket.BeginConnect(ipAddress, DEFAULT_PORT, ConnectedCallback, ss); return(socket); }
/// <summary> /// The socket state constructor that initializes what socket, id, and delegate /// will be passed around in the Network Controller and Game Controller. /// </summary> /// <param name="s"></param> /// <param name="_id"></param> /// <param name="callMeParameter"></param> public ConnectionState(callMeDelegate callMeParameter, TcpListener _listener) { callMe = callMeParameter; listener = _listener; }