Did anyone work with Lidgren.Portable yet?

Hello Game Developers,
i just had to switch to Lidgren.Portable to get the game Networking in Windows Store.

Well there is a Nuget Package which distributes Version 1.0.1 of it. I did not find any Topics on how to use it, so i tried to use it as i used to use the “full” Lidgren Lib, which is as following to connect:

NetPeerConfiguration config = new NetPeerConfiguration(“BMM”);
NetClient client = new NetClient(config);
client.Connect(“”, port);

Now here is the Problem: Connect says

throw new NetException(“Must call Start() first”);

and Start says:

	public void Start()

I guess this is not how i am supposed to work with lidgren anymore, but how would i use it? Whats the proper way to connect anywhere in Lidgren.Portable?

Would love to get some hints.

Thanks and bye,

edit 19.8: Changed “Monogame.Portable” to “Lidgren.Portable”. Sorry did confuse those 2 when creating the thread.

For anyone else to look after a Windows UAP version of Lidgren: to my Research and Knowledge there is currently None (24. of July 2015). Did end up creating my own Network Communication classes using StreamSocket, which is the new TcpListener.


It says on the NuGet page for it that the Lidgren PCL package that it’s only a stub, to have the actual functions implemented on a per-platform basis.

If you’re still interested, I would be interested in getting the specifics for this worked out. If not, I’d be interested in knowing what you’re doing instead.

(But it’s almost 02:00 here and I need sleep to be very useful for any programming related anything)

I hope you got enough sleep when you read this. It’s now 12 AM for me, so i guess we will live on opposide sides of the world :slight_smile:

Anyway, i am interested in getting the portable Lidgren working, but i am concerned about the time i will spend to implement and test it. For now, i used StreamSockets, which work as followed:

connect somewhere:

socket = new StreamSocket(); await socket.ConnectAsync(new HostName(host), port);

Note: host can now be a string containing a hostname OR an IP.

Receive stuff:

public static async void StartReceiveData(StreamSocket socket, IDataReceivedCallback callback) { bool connected = true; string disconectReason = string.Empty; using (var dr = new DataReader(socket.InputStream)) { while (connected) { try { var stringHeader = await dr.LoadAsync(4); if (stringHeader == 0) { connected = false; disconectReason = "Regular disconect"; } int strLength = dr.ReadInt32(); uint numStrBytes = await dr.LoadAsync((uint)strLength); string msg = dr.ReadString(numStrBytes); var obj = Serializer.DeserializeFromString(msg); if (obj != null) { callback.DataInput(obj, socket); } } catch (Exception e) { connected = false; disconectReason = e.Message; } } } callback.Disconnected(socket, disconectReason); }

public interface IDataReceivedCallback
void DataInput(object obj, StreamSocket socket);

    void Disconnected(StreamSocket socket, string reason);

Send Stuff:

public static async void SendToSocket(StreamSocket socket, object obj) { string strObj = Serializer.SerializeToString(obj);
        if (socket != null)
            using (var dw = new DataWriter(socket.OutputStream))
                Int32 len = (int)dw.MeasureString(strObj);

                await dw.StoreAsync();


This works pretty well to Exchange simple C# objects, and is enough for me to provide a Lobby and game communication. I will add UDP Support (UDPClient) for faster game communication, but for now this is enough to test game and Networking logic.

Okay. After trying a few other random things, what it seems to be is:
Add the PCL Library version of Ligren to the Portable project, then on the platform native application, add a copy of ligren for that platform as (I haven’t tested it with anything other than the basic Lidgren library on linux yet).
I’m not sure about the specifics of your project, but it looks like this could mean having to adapt Lidgren to other platforms, depending on the networking. If not, just Reference the normal Lidgren project against each of the native applications, and enjoy!

I can not use the native Lidgren lib, as it is prohibited by the ProjectType of Windows Store Applications. Windows Store Applications use a reduced set of APIs, which do not include those used in the original Lidgren Lib.

Looks like i need to stay with my proprietary classes until the portable lidgren lib for Windows UAP got coded out