{"id":27633739,"url":"https://github.com/djaus2/socketsuwp","last_synced_at":"2025-08-19T02:43:05.782Z","repository":{"id":85177358,"uuid":"187439897","full_name":"djaus2/SocketsUWP","owner":"djaus2","description":"UWP TCPIP Sockets library for Socket Client and Server. Includes sample Client and Server apps.","archived":false,"fork":false,"pushed_at":"2019-05-19T13:47:29.000Z","size":2463,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T18:19:22.646Z","etag":null,"topics":["class","l","socket-client","socket-server","sockets","uwp"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/djaus2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-19T06:01:15.000Z","updated_at":"2021-06-24T15:27:19.000Z","dependencies_parsed_at":"2023-03-13T04:36:21.786Z","dependency_job_id":null,"html_url":"https://github.com/djaus2/SocketsUWP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/djaus2/SocketsUWP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FSocketsUWP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FSocketsUWP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FSocketsUWP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FSocketsUWP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/djaus2","download_url":"https://codeload.github.com/djaus2/SocketsUWP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/djaus2%2FSocketsUWP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271092129,"owners_count":24697903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["class","l","socket-client","socket-server","sockets","uwp"],"created_at":"2025-04-23T18:19:21.364Z","updated_at":"2025-08-19T02:43:05.708Z","avatar_url":"https://github.com/djaus2.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SocketsUWP\nA High Level UWP TCPIP Sockets library for Socket Client and Server. Includes sample Client and Server apps.\n\n## History\n*This project extends some of the code from my [SurfPad Project](https://github.com/djaus2/SurfPad) which provides for a UWP UI app running on a Windows Surface running as a remote control for a Windows 10 IoT-Core device. Communication between the two has various transports as options using Bluetooth, USB and TCPIP Sockets. This project refactors the Sockets into a reusable library.*\n\n# About\nThe project consists of 3 subprojects:\n- **SocketsWP**: UWP Class library. Contains the Socket Client and Server classes\n- **TestSocketClient**: XAML-UWP The Client test app\n- **TestSocketSVR**: XAML-UWP The Server test app\n\nTo add Socket capability to a a UWP app you include the **SocketsUWP** class library project in the app's solution \nand make reference to it by the app. If you want the app to be the socket client you initiate the **SocketSvrV2** class. \nOtherwise you instatiate the **SocketCientV2** class for a Client app.\n\nThe client and server class both contain methods for asynchronous sending and receiving of messages.\nString messages are are sent as lines using WriteLine and so the receiving end reads until the string is terminated by a new line (which is removed), using ReadLine. There is also a capability to send and receive chars as you might do in a command mode.\nFinally, there is a a mode to send and receive a buffer (as an array of chars). \n\nThe client and server need the same TCPIP port setting of course (set to default to 1234 in the Common class). The server starts in a listening mode. The client intiates. There is some handshaking where both end send some characters and the other end expects and receives certain characters. \nThe server only supports one connection at a time, as doe sthe client.\n\nThe Client and Server classes use delegates to communicate back to the hosting app when data is received.\n\n*In the class namespace:*\n```\npublic delegate void ActionReceivedText(string recvTxt);\n```\n*In the class:*\n\n```\n public ActionReceivedText OnRecvdText = null;\n\n//Having got a message:\n OnRecvdText?.Invoke(response);\n```\n*In the app:*\n```\nsocketSvr.OnRecvdText = OnrecvText;\n\n//The OnrecvText method:\nprivate void OnrecvText(string recvTxt)\n{\n    Task.Run(async () =\u003e\n    {\n        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =\u003e\n        {\n            tb4.Text = recvTxt;\n        });\n    });\n}\n```\n\n#### NB:\nThere are four characters reserved for commands which should not be the first character of any message. These are listed in the Common class.\nThey should be esacaped in used in messages. Add to this list newline characters.\n\n# Target Platforms\nWindows 10 Desktop x64,x86, IoT-Core x64,x86 and ARM32, Windows Phone 10.\n\n##### *NB:*\n*The Target Windows version is Creators Update (15063). That way the app can be deployed to Windows Phones.\nThere is plenty of lattitude though as to what target build you use. The librray and app build need to match of course.*\n\n## ToDos\n- Enable Cancellation of Socket IO.\n- Automatically esacpe command characters.\n- Create a **NuGet** package for the class library\n- Some refactoring of code, especially of common functionality between the client and server classes.\n\n### Hint:\nI run the server on my desktop. \nIn my Broadband modem WAN settings at home, I direct the port to my dektop. \nThen I can communicate with the server from my phone, laptop or IoT-Core device when connected to the internet anywhere; subject to routing port restrictions in the mobile device's location.\n\n*This can be a way also for getting around the UWP restriction of apps running on the same host can't communicate over TCPIP. They way you can start both apps simulataneously in Debug mode on the desktop and set teh IP of the host in the Clientto your Broadband WAN IP Address.*\n\n[Ref:](https://docs.microsoft.com/en-us/windows/uwp/networking/sockets)\n\u003e [!NOTE]\n\u003e As a consequence of [network isolation](https://msdn.microsoft.com/library/windows/apps/hh770532.aspx), Windows disallows establishing a socket connection (Sockets or WinSock) between two UWP apps running on the same machine; whether that's via the local loopback address (127.0.0.0), or by explicitly specifying the local IP address. For details about mechanisms by which UWP apps can communicate with one another, \n\u003e see [App-to-app communication](https://docs.microsoft.com/en-us/windows/uwp/app-to-app/index).\n\nI also use an X64 Windows 10-IoT-Core device, running nearby my desktop as my second target during development\n\n# Usage\nCreate a new UWP app project. Include the libabry in your app solution and refrence it. Add Internte/Network Capabilities to the app's Package.appmanifest. NB: For IoT-Core there is no need for IOT Extensions. for the Sockets.\n\n## Server\nInstantiate the SocketSvr class. \nImplment the **OnrecvText** method in the main app and assign it to the server instance *(Same for OnrecvBuffer)*.\nUse the following interface to it:\n```\n    public interface ISocketServerV2\n    {\n        string HostIP { get; }\n\n        // static string PortNumber { get; set; }\n\n        Task Action_Cmd(string command, string optionalParam = \"\");\n        Task SendBuffer(char[] request);\n        Task SendCh(char ch);\n    }\n```\nThe main Client Action commands  are:\n- \"Start Listening\"\n- \"Stop Listening\"\n- \"Send Line\"\n- \"Send Buffer\"\n\nThe Port needs to be set before starting the service. \nIt is a static property to the class enabling it to be set before the class is instatiated. The app can get and display its IP Address once the service is started.\nThe last two commands require a suitable parameter.\n\n## Client\nInstantiate the SocketClient class. \nImplment the **OnrecvText** method in the main app and assign it to the server instance. *(Same for OnrecvBuffer)*\nUse the following interface to it:\n```\n    public interface ISocketClientV2\n    {\n        string Host { get; set; }\n        string Port { get; set; }\n        Task Action_Cmd(string command, string optionalParam = \"\");\n    }\n```\nThe main Client Action commands  are:\n- \"Connect\"\n- \"Disconnect\"\n- \"Send Line\"\n- \"Send Buffer\"\n\nThe Host and Port need to be set before connecting. \nThe last two commands require a suitable parameter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjaus2%2Fsocketsuwp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdjaus2%2Fsocketsuwp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdjaus2%2Fsocketsuwp/lists"}