Transfer binary files from server to client and vice versa

I have setup a server client connection using bolt and I'm trying to send a binary file across the two. I referred Streaming Bytes documentation but it doesn't explain where the channels have to be created and from where(code or file) it has to send. If you have any examples or samples relating to sending files, please share!

Answers

  • 0bytedna0bytedna
    edited June 1
    [BoltGlobalBehaviour] public class NetworkCallbacks : Bolt.GlobalEventListener { //Stream Channel UdpChannelName Lobby_Main; //Variable to be streamed Dictionary <string , PlayerInfo > Players = new Dictionary< string , PlayerInfo > (); public static NetworkCallbacks Instance; void Awake () { Instance = this; } public override void BoltStartBegin () { Lobby_Main = BoltNetwork.CreateStreamChannel ("Lobby_Main", UdpKit.UdpChannelMode.Reliable, 4); } public void StreamLobbyData () { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream ()) { bf.Serialize (ms, Players); foreach (BoltConnection item in BoltNetwork.clients) { item.StreamBytes (Lobby_Main, ms.ToArray ()); } } } public override void Connected (BoltConnection connection) { connection.SetStreamBandwidth (1024 * 20); } public override void StreamDataReceived (BoltConnection connnection, UdpStreamData data) { if (BoltNetwork.isClient) { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream (data.Data)) { Players = (Dictionary<string, PlayerInfo>)bf.Deserialize (ms); } } }



    I call StreamLobbyData function whenever i wanna stream data from server to all clients
  • [BoltGlobalBehaviour] public class NetworkCallbacks : Bolt.GlobalEventListener { //Stream Channel UdpChannelName Lobby_Main; //Variable to be streamed Dictionary <string , PlayerInfo > Players = new Dictionary< string , PlayerInfo > (); public static NetworkCallbacks Instance; void Awake () { Instance = this; } public override void BoltStartBegin () { Lobby_Main = BoltNetwork.CreateStreamChannel ("Lobby_Main", UdpKit.UdpChannelMode.Reliable, 4); } public void StreamLobbyData () { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream ()) { bf.Serialize (ms, Players); foreach (BoltConnection item in BoltNetwork.clients) { item.StreamBytes (Lobby_Main, ms.ToArray ()); } } } public override void Connected (BoltConnection connection) { connection.SetStreamBandwidth (1024 * 20); } public override void StreamDataReceived (BoltConnection connnection, UdpStreamData data) { if (BoltNetwork.isClient) { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream (data.Data)) { Players = (Dictionary<string, PlayerInfo>)bf.Deserialize (ms); } } }



    I call StreamLobbyData function whenever i wanna stream data from server to all clients
  • [BoltGlobalBehaviour] public class NetworkCallbacks : Bolt.GlobalEventListener { //Stream Channel UdpChannelName Lobby_Main; //Variable to be streamed Dictionary <string , PlayerInfo > Players = new Dictionary< string , PlayerInfo > (); public static NetworkCallbacks Instance; void Awake () { Instance = this; } public override void BoltStartBegin () { Lobby_Main = BoltNetwork.CreateStreamChannel ("Lobby_Main", UdpKit.UdpChannelMode.Reliable, 4); } public void StreamLobbyData () { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream ()) { bf.Serialize (ms, Players); foreach (BoltConnection item in BoltNetwork.clients) { item.StreamBytes (Lobby_Main, ms.ToArray ()); } } } public override void Connected (BoltConnection connection) { connection.SetStreamBandwidth (1024 * 20); } public override void StreamDataReceived (BoltConnection connnection, UdpStreamData data) { if (BoltNetwork.isClient) { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream (data.Data)) { Players = (Dictionary<string, PlayerInfo>)bf.Deserialize (ms); } } }



    I call StreamLobbyData function whenever i wanna stream data from server to all clients
  • [BoltGlobalBehaviour] public class NetworkCallbacks : Bolt.GlobalEventListener { //Stream Channel UdpChannelName Lobby_Main; //Variable to be streamed Dictionary <string , PlayerInfo > Players = new Dictionary< string , PlayerInfo > (); public static NetworkCallbacks Instance; void Awake () { Instance = this; } public override void BoltStartBegin () { Lobby_Main = BoltNetwork.CreateStreamChannel ("Lobby_Main", UdpKit.UdpChannelMode.Reliable, 4); } public void StreamLobbyData () { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream ()) { bf.Serialize (ms, Players); foreach (BoltConnection item in BoltNetwork.clients) { item.StreamBytes (Lobby_Main, ms.ToArray ()); } } } public override void Connected (BoltConnection connection) { connection.SetStreamBandwidth (1024 * 20); } public override void StreamDataReceived (BoltConnection connnection, UdpStreamData data) { if (BoltNetwork.isClient) { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream (data.Data)) { Players = (Dictionary<string, PlayerInfo>)bf.Deserialize (ms); } } }



    I call StreamLobbyData function whenever i wanna stream data from server to all clients
  • [BoltGlobalBehaviour] public class NetworkCallbacks : Bolt.GlobalEventListener { //Stream Channel UdpChannelName Lobby_Main; //Variable to be streamed Dictionary <string , PlayerInfo > Players = new Dictionary< string , PlayerInfo > (); public static NetworkCallbacks Instance; void Awake () { Instance = this; } public override void BoltStartBegin () { Lobby_Main = BoltNetwork.CreateStreamChannel ("Lobby_Main", UdpKit.UdpChannelMode.Reliable, 4); } public void StreamLobbyData () { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream ()) { bf.Serialize (ms, Players); foreach (BoltConnection item in BoltNetwork.clients) { item.StreamBytes (Lobby_Main, ms.ToArray ()); } } } public override void Connected (BoltConnection connection) { connection.SetStreamBandwidth (1024 * 20); } public override void StreamDataReceived (BoltConnection connnection, UdpStreamData data) { if (BoltNetwork.isClient) { BinaryFormatter bf = new BinaryFormatter (); using (MemoryStream ms = new MemoryStream (data.Data)) { Players = (Dictionary<string, PlayerInfo>)bf.Deserialize (ms); } } }



    I call StreamLobbyData function whenever i wanna stream data from server to all clients
Sign In or Register to comment.