/// <summary> /// Send a stream to a single connected client. /// </summary> /// <returns><c>true</c>, if stream was sent, <c>false</c> otherwise.</returns> /// <param name="buffer">The object to serialize and stream.</param> /// <param name="size">Max buffer size of object after being serialized.</param> /// <param name="channel">Channel to broadcast on.</param> /// <param name="connId">Connection ID of client to broadcast to.</param> public bool SendStream(byte[] buffer, int size, int connId, int channel) { byte error; NetworkTransport.Send(mSocket, connId, channel, buffer, size, out error); if (NetUtils.IsNetworkError(error)) { Debug.Log("NetServer::SendStream( " + buffer.ToString() + " , " + size.ToString() + " ) Failed with reason '" + NetUtils.GetNetworkError(error) + "'."); return(false); } return(true); }
/// <summary> /// Connect the specified ip and port. /// </summary> /// <param name="ip">Ip.</param> /// <param name="port">Port.</param> public bool Connect(string ip, int port) { byte error; mConnection = NetworkTransport.Connect(mSocket, ip, port, 0, out error); if (NetUtils.IsNetworkError(error)) { Debug.Log("NetClient::Connect( " + ip + " , " + port.ToString() + " ) Failed with reason '" + NetUtils.GetNetworkError(error) + "'."); return(false); } mServerIP = ip; mPort = port; return(true); }
/// <summary> /// Disconnects a client via specified id. /// </summary> /// <returns><c>true</c>, if client was disconnected, <c>false</c> otherwise.</returns> public bool DisconnectClient(int connId) { if (!HasClient(connId)) { Debug.Log("NetServer::DisconnectClient( " + connId + " ) Failed with reason 'Client with id does not exist!'"); return(false); } byte error; NetworkTransport.Disconnect(mSocket, connId, out error); if (NetUtils.IsNetworkError(error)) { Debug.Log("NetServer::DisconnectClient( " + connId + " ) Failed with reason '" + NetUtils.GetNetworkError(error) + "'."); return(false); } return(true); }
/// <summary> /// Disconnect the client from the server. /// </summary> public bool Disconnect() { if (!mIsConnected) { Debug.Log("NetClient::Disconnect() Failed with reason 'Not connected to server!"); return(false); } byte error; NetworkTransport.Disconnect(mSocket, mConnection, out error); if (NetUtils.IsNetworkError(error)) { Debug.Log("NetClient::Disconnect() Failed with reason '" + NetUtils.GetNetworkError(error) + "'."); return(false); } mIsConnected = false; return(true); }