{"id":16239144,"url":"https://github.com/xtrinch/socket-live","last_synced_at":"2025-03-19T16:31:15.778Z","repository":{"id":57742990,"uuid":"107836353","full_name":"xtrinch/socket-live","owner":"xtrinch","description":"Java TCP/IP socket communication library","archived":false,"fork":false,"pushed_at":"2017-11-26T22:29:08.000Z","size":30,"stargazers_count":10,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T09:05:43.454Z","etag":null,"topics":["java-sockets","sockets","thread"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xtrinch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-22T04:08:22.000Z","updated_at":"2024-04-11T11:36:43.000Z","dependencies_parsed_at":"2022-09-11T10:40:58.778Z","dependency_job_id":null,"html_url":"https://github.com/xtrinch/socket-live","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtrinch%2Fsocket-live","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtrinch%2Fsocket-live/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtrinch%2Fsocket-live/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xtrinch%2Fsocket-live/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xtrinch","download_url":"https://codeload.github.com/xtrinch/socket-live/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244463725,"owners_count":20456934,"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","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":["java-sockets","sockets","thread"],"created_at":"2024-10-10T13:42:27.751Z","updated_at":"2025-03-19T16:31:15.481Z","avatar_url":"https://github.com/xtrinch.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maven Central](https://maven-badges.herokuapp.com/maven-central/si.trina/socket-live/badge.svg)](https://maven-badges.herokuapp.com/maven-central/si.trina/socket-live)\n\n\n# socket-live\n\nJava library for TCP/IP socket communication. \n\nConsists of three main components (which later result into three running threads):\n\n  * SocketConnection.java: main thread, run by the user of the library, which makes sure the connection is always open\n  * SocketRead.java: read thread which continuously attempts to read incoming messages if any\n  * SocketWrite.java: write thread which writes any messages in write queue to socket\n\n## Installation\n\nPackage can be installed via maven by adding the following to your pom.xml:\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003esi.trina\u003c/groupId\u003e\n        \u003cartifactId\u003esocket-live\u003c/artifactId\u003e\n        \u003cversion\u003e0.0.3\u003c/version\u003e\n    \u003c/dependency\u003e\n    \n## How to use\n\n**Initialize the socket connection**\n\n    /*\n        args: \n            ** name of socket connection\n            ** IP of socket endpoint\n            ** port of socket endpoint\n    */\n    SocketConnection example = new SocketConnection(\"m3scan-channel1\", \"10.0.0.2\", 5040);    \n    new Thread(example).start();\n\n**Add listeners to socket connection**\n\n    public class MyListener implements SocketListener {\n        @Override\n        public void processSocketEvent(byte[] data, SocketConnection connection) {\n\t\tshort aShort = connection.byteArrayToUInt16(new byte[] {data[0],reply[data[1]]});\n\t\tbyte[] stringByteArray = Arrays.copyOfRange(data,data[2],data[20]);\n\t\tString aString = connection.byteArrayToString(stringByteArray);\n           ...\n        }\n    }\n    \n    MyListener listener = new MyListener();\n    example.addListener(listener);\n    \nNote that read thread expects an integer (4 bytes) with byte length of message before every message.\n\n**Send data to socket**\n\n    ByteArrayOutputStream os = new ByteArrayOutputStream();\n\n    os.write(example.intToByteArray(42)); // for example: datagram length in bytes\n\n    os.write(example.uint16ToByteArray((short)1)); // 1, 2, 3\n    os.write(example.stringToByteArray(\"test\", 40));\n\n    example.sendToServer(os.toByteArray());\n    \n\n### Optional parameters of SocketConnection instance\n\n**charsetName**\n\nString indicating which charset to use when encoding/decoding strings (Java Charset strings apply).\n\n**reconnectInterval**\n\nLong indicating how often should connection attempt to be restored in case of target endpoind disconnecting.\n\n**checkConnectionInterval**\n\nLong indicating how often should the connection status be checked. Checking the connection status will result in attempting to reconnect if disconnected.\n\n**readEnabled**\n\nIn case only writing to socket is required, this boolean can be set to false.\n\n**writeEnabled**\n\nIn case only reading from socket is required, this boolean can be set to false.\n\n## Logging\n\nAll logging with various priorities inside the library is done with slf4j. Meaning, you need a logger binding (for example slf4j-simple) to see logs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtrinch%2Fsocket-live","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxtrinch%2Fsocket-live","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxtrinch%2Fsocket-live/lists"}