kandi background
Explore Kits

socket.core | socket framework based on C # net standard2 | TCP library

 by   fengma312 C# Version: v1.0.14 License: Apache-2.0

 by   fengma312 C# Version: v1.0.14 License: Apache-2.0

Download this library from

kandi X-RAY | socket.core Summary

socket.core is a C# library typically used in Networking, TCP applications. socket.core has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.
socket.core === this is a socket framework based on c # net standard2.0 write, can be used for .net framework / dotnet core assembly, can run in window (iocp) / linux (epoll) .use asynchronous connection, asynchronous send, asynchronous receive, performance burst tables, and pass the stress test. .net framework4.0 version https://github.com/fengma312/socket.framework ---. install nuget: https://www.nuget.org/packages/socket.core/ package manager: install-package socket.core .net cli: dotnet add package socket.core paket cli: paket add socket.core one: tcp module introduction server socket.core.server namespace, respectively, three modes push / pull / pack under the socket.core. client namespace of the client, there are three modes of push / pull / pack. the main process and the corresponding methods and events introduced. note: connectid (guid) represents a connection object, data (byte []), success (bool)    * 1. initialize socket (corresponding to the three modes) >instantiate the server class tcppushserver / tcppullserver / tcppackserver >instantiate the client class tcppushclient / tcppullclient / tcppackclient >parameter introduction int numconnections maximum number of simultaneous connections, int receivebuffersize buffer size (sink) for each socket i / o operation, int overtime timeout period in seconds (check every 10 seconds), when the value is 0, do not set the timeout, uint headerflag header tag range 0 ~ 1023 (0x3ff), when the header identifier is equal to 0, do not check the header *
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • socket.core has a low active ecosystem.
  • It has 209 star(s) with 93 fork(s). There are 25 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 0 open issues and 16 have been closed. On average issues are closed in 12 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of socket.core is v1.0.14
socket.core Support
Best in #TCP
Average in #TCP
socket.core Support
Best in #TCP
Average in #TCP

quality kandi Quality

  • socket.core has 0 bugs and 0 code smells.
socket.core Quality
Best in #TCP
Average in #TCP
socket.core Quality
Best in #TCP
Average in #TCP

securitySecurity

  • socket.core has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • socket.core code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
socket.core Security
Best in #TCP
Average in #TCP
socket.core Security
Best in #TCP
Average in #TCP

license License

  • socket.core is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
socket.core License
Best in #TCP
Average in #TCP
socket.core License
Best in #TCP
Average in #TCP

buildReuse

  • socket.core releases are available to install and integrate.
  • Installation instructions are not available. Examples and code snippets are available.
socket.core Reuse
Best in #TCP
Average in #TCP
socket.core Reuse
Best in #TCP
Average in #TCP
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

socket.core Key Features

1. Initialize the UDP implementation class UdpServer / UdpClients >Server socket.core.Server.UdpServer >Client socket.core.Client.UdpClients >Parameters int receiveBufferSize Buffer size for each socket I / O operation (receiver)

2. Send data >Server server.Send (remoteEndPoint, data, offset, length) >Client client.Send (data, offset, length) >Client client.Send(remoteEndPoint,data,offset,length)

3. Trigger sent events >Server server.OnSend (remoteEndPoint, length) >Client client.OnSend (length)

3. Trigger the receiving event >Server server.OnReceive (remoteEndPoint, data, offset, length) >Client client.OnReceive (data, offset, length)

1.初始化TCP实现类(对应的三种模式) >实例化服务端类 TcpPushServer/TcpPullServer/TcpPackServer >实例化客户端类 TcpPushClient/TcpPullClient/TcpPackClient >参数介绍int numConnections同时处理的最大连接数,int receiveBufferSize用于每个套接字I/O操作的缓冲区大小(接收端), int overtime超时时长,单位秒.(每10秒检查一次),当值为0时,不设置超时,uint headerFlag包头标记范围0~1023(0x3FF),当包头标识等于0时,不校验包头

2.启动监听/连接服务器 >服务端 server.Start(port); >客户端 client.Connect(ip,port);

3.触发连接事件 >服务端 server.OnAccept(connectId); 接收到一个连接id,可用他来发送,接收,关闭的标记 >客户端 client.OnConnect(success); 接收是否成功连接到服务器

4.发送消息 >服务端 server.Send(connectId,data,offset,length); >客户端 client.Send(data,offset,length);

5.触发已发送事件 >服务端 server.OnSend(connectId,length); >客户端 client.OnSend(length);

6.触发接收事件 >服务端 server.OnReceive(connectId, data); >客户端 client.OnReceive(data);

7.关闭连接 >服务端 server.Close(connectId); >客户端 client.Close();

8.触发关闭连接事件 >服务端 server.OnClose(connectId); >客户端 client.OnClose();

1.初始化UDP实现类UdpServer/UdpClients >服务端socket.core.Server.UdpServer >客户端socket.core.Client.UdpClients >参数int receiveBufferSize用于每个套接字I/O操作的缓冲区大小(接收端)

2.发送数据 >服务端 server.Send(remoteEndPoint,data,offset,length) >客户端 client.Send(data,offset,length) >客户端 client.Send(remoteEndPoint,data,offset,length)

3.触发已发送事件 >服务端 server.OnSend(remoteEndPoint,length) >客户端 client.OnSend(length)

3.触发接收事件 >服务端 server.OnReceive(remoteEndPoint,data,offset,length) >客户端 client.OnReceive(data,offset,length) 2017/12/27 技术在于分享,大家共同进步

socket.core Examples and Code Snippets

See all related Code Snippets

default

copy iconCopydownload iconDownload
2017/12/27

RSocket and Spring not handle multiple requests

copy iconCopydownload iconDownload
.delayElements(Duration.ofSeconds(10));

RSocket Android + Spring Boot back-end routing error: No handler for destination ''

copy iconCopydownload iconDownload
    private fun getPayload(route: String, message: String): Payload {
        val metadata = ByteBufAllocator.DEFAULT.compositeBuffer()
        val routingMetadata =
            TaggingMetadataCodec.createRoutingMetadata(ByteBufAllocator.DEFAULT, listOf(route))
        CompositeMetadataCodec.encodeAndAddMetadata(
            metadata,
            ByteBufAllocator.DEFAULT,
            WellKnownMimeType.MESSAGE_RSOCKET_ROUTING,
            routingMetadata.content
        )
        val data = ByteBufAllocator.DEFAULT.buffer().writeBytes(message.toByteArray())

        return DefaultPayload.create(data, metadata)
    }

    private fun connect(route: String, message: String): String? = runBlocking {
        withContext(Dispatchers.IO) {

            val ws: WebsocketClientTransport =
                WebsocketClientTransport.create(URI.create(hostUrl))
            val clientRSocket = RSocketConnector.create()
                //metadata header needs to be specified
                .metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.string)
                // value of spring.rsocket.server.port eg 7000
                .connect(ws)
                .block()
            return@withContext try {
                val s = clientRSocket?.requestResponse(getPayload(route, message))
                s?.block()?.dataUtf8
            } catch (e: Exception) {
                Log.e("net", "RSocket cannot connect: ", e)
                e.asString()
            } finally {
                clientRSocket?.dispose()
            }

        }
    }

PANIC: unprotected error in call to Lua API (undefined symbol: lua_gettop)

copy iconCopydownload iconDownload
FROM gcc:11.1.0
RUN wget https://www.lua.org/ftp/lua-5.4.2.tar.gz \
 && git clone https://github.com/diegonehab/luasocket.git
RUN tar zxf lua-5.4.2.tar.gz \
 && cd lua-5.4.2 \
 && make linux \
 && make install \
 && cd ../luasocket \
 && git checkout 5b18e475f38fcf28429b1cc4b17baee3b9793a62 \
 && make linux LUAV=5.4 \
 && make install LUAV=5.4
COPY test.lua main.c ./
MYLDFLAGS= $(LOCAL) -Wl,-E
root@077bbb831441:/# gcc -o test main.c /usr/local/lib/liblua.a -ldl -lm -Wl,-rpath='/usr/local/lib/lua/5.4/socket' -Wl,-E && ./test
lua enter
LuaSocket 3.0-rc1
lua exit

FROM gcc:11.1.0
RUN wget https://www.lua.org/ftp/lua-5.4.2.tar.gz \
 && git clone https://github.com/diegonehab/luasocket.git
RUN tar zxf lua-5.4.2.tar.gz \
 && cd lua-5.4.2 \
 && make linux \
 && make install \
 && cd ../luasocket \
 && git checkout 5b18e475f38fcf28429b1cc4b17baee3b9793a62 \
 && make linux LUAV=5.4 \
 && make install LUAV=5.4
COPY test.lua main.c ./
MYLDFLAGS= $(LOCAL) -Wl,-E
root@077bbb831441:/# gcc -o test main.c /usr/local/lib/liblua.a -ldl -lm -Wl,-rpath='/usr/local/lib/lua/5.4/socket' -Wl,-E && ./test
lua enter
LuaSocket 3.0-rc1
lua exit

FROM gcc:11.1.0
RUN wget https://www.lua.org/ftp/lua-5.4.2.tar.gz \
 && git clone https://github.com/diegonehab/luasocket.git
RUN tar zxf lua-5.4.2.tar.gz \
 && cd lua-5.4.2 \
 && make linux \
 && make install \
 && cd ../luasocket \
 && git checkout 5b18e475f38fcf28429b1cc4b17baee3b9793a62 \
 && make linux LUAV=5.4 \
 && make install LUAV=5.4
COPY test.lua main.c ./
MYLDFLAGS= $(LOCAL) -Wl,-E
root@077bbb831441:/# gcc -o test main.c /usr/local/lib/liblua.a -ldl -lm -Wl,-rpath='/usr/local/lib/lua/5.4/socket' -Wl,-E && ./test
lua enter
LuaSocket 3.0-rc1
lua exit

See all related Code Snippets

Community Discussions

Trending Discussions on socket.core
  • RSocket and Spring not handle multiple requests
  • RSocket Android + Spring Boot back-end routing error: No handler for destination ''
  • PANIC: unprotected error in call to Lua API (undefined symbol: lua_gettop)
  • How to handle inbound stream cancellation in Spring Boot RSocket Reactive
  • RSocket channel error : "reactor.core.publisher.Operators.error - Operator called default onErrorDropped" with merged flux
Trending Discussions on socket.core

QUESTION

RSocket and Spring not handle multiple requests

Asked 2021-Sep-01 at 16:38

I play with RSocket together with Spring boot. I want to make simple request-response example. As example I took code from this link:

https://www.baeldung.com/spring-boot-rsocket#request-response

Source code:

https://github.com/eugenp/tutorials/tree/master/spring-5-webflux/src/main/java/com/baeldung/spring/rsocket

When I run example code without change I get error during request with Exception. This error is not point of this question, but I just want to show changes comapre to original source by baeldung.

[reactor-tcp-nio-1] org.springframework.core.log.CompositeLog: [5927a44d-9] 500 Server Error for HTTP GET "/current/pko" io.rsocket.exceptions.ApplicationErrorException: No handler for destination '' at io.rsocket.exceptions.Exceptions.from(Exceptions.java:76) Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s): |_ checkpoint ⇢ Handler com.baeldung.spring.rsocket.client.MarketDataRestController#current(String) [DispatcherHandler] |_ checkpoint ⇢ HTTP GET "/current/pko" [ExceptionHandlingWebHandler] Stack trace: at io.rsocket.exceptions.Exceptions.from(Exceptions.java:76) at io.rsocket.core.RSocketRequester.handleFrame(RSocketRequester.java:706) at io.rsocket.core.RSocketRequester.handleIncomingFrames(RSocketRequester.java:640) at reactor.core.publisher.LambdaSubscriber.onNext(LambdaSubscriber.java:160) at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:242) at reactor.core.publisher.FluxGroupBy$UnicastGroupedFlux.drainRegular(FluxGroupBy.java:554) at reactor.core.publisher.FluxGroupBy$UnicastGroupedFlux.drain(FluxGroupBy.java:630) at reactor.core.publisher.FluxGroupBy$UnicastGroupedFlux.onNext(FluxGroupBy.java:670) at reactor.core.publisher.FluxGroupBy$GroupByMain.onNext(FluxGroupBy.java:205) at reactor.core.publisher.FluxHandle$HandleSubscriber.onNext(FluxHandle.java:112) at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:213) at reactor.core.publisher.FluxMap$MapConditionalSubscriber.onNext(FluxMap.java:213) at reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:260) at reactor.netty.channel.FluxReceive.onInboundNext(FluxReceive.java:366) at reactor.netty.channel.ChannelOperations.onInboundNext(ChannelOperations.java:358) at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:96) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834)

So I change client code from

@Configuration
public class ClientConfiguration {

    @Bean
    public RSocket rSocket() {
        return RSocketFactory.connect()
                             .mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE)
                             .frameDecoder(PayloadDecoder.ZERO_COPY)
                             .transport(TcpClientTransport.create(7000))
                             .start()
                             .block();
    }

    @Bean
    RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
        return RSocketRequester.wrap(rSocket(), MimeTypeUtils.APPLICATION_JSON, MimeTypeUtils.APPLICATION_JSON, rSocketStrategies);
    }
}

to

@Configuration
public class ClientConfiguration {
    

    @Bean
    RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
        return RSocketRequester.builder()
                .rsocketStrategies(rSocketStrategies)
                .connectTcp("localhost", 7000)
                .block();
    }
}

This small change help, an exception does not occur. Other issue that is point of that question iis that requests from client(requester) are processed one by one by server(responder). I create SOAPUI REST project and run GET request in 2 thread. It look like server use single thread. This is not what I expect to achieve.

To make it easy I will show whole solution.

Server :

Simple controller

@Controller
public class MarketDataRSocketController {

    Logger logger = LoggerFactory.getLogger(MarketDataRSocketController.class);

    private final MarketDataRepository marketDataRepository;

    public MarketDataRSocketController(MarketDataRepository marketDataRepository) {
        this.marketDataRepository = marketDataRepository;
    }

    @MessageMapping("currentMarketData")
    public Mono<MarketData> currentMarketData(MarketDataRequest marketDataRequest) {
        logger.info("Getting data for: "+marketDataRequest);
        Mono<MarketData> result = marketDataRepository.getOne(marketDataRequest.getStock());
        logger.info("Controller thread move forward: "+marketDataRequest);
        return result;
    }

    @MessageExceptionHandler
    public Mono<MarketData> handleException(Exception e) {
        return Mono.just(MarketData.fromException(e));
    }
}

In repository I add Thread.sleep(10000); just to simulate long running operation.

@Component
public class MarketDataRepository {
    Logger logger = LoggerFactory.getLogger(MarketDataRSocketController.class);
    private static final int BOUND = 100;
    private Random random = new Random();

    public Mono<MarketData> getOne(String stock) {
        //return return Mono.just(getMarketDataResponse(stock)); original code from baeldung.
        return Mono.just(stock).map(s -> getMarketDataResponse(s));
    }

    private MarketData getMarketDataResponse(String stock) {
        logger.info("Repository thread go speel ZzzZZ");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        logger.info("Repository thread move forward");
        return new MarketData(stock, random.nextInt(BOUND));
    }
}

Client

Simple client configuration:

@Configuration
public class ClientConfiguration {


    @Bean
    RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
        return RSocketRequester.builder()
                .rsocketStrategies(rSocketStrategies)
                .connectTcp("localhost", 7000)
                .block();
    }
}

And simple REST Controller that I use in SOAP UI

@RestController
public class MarketDataRestController {
    Logger logger = LoggerFactory.getLogger(MarketDataRestController.class);

    private final Random random = new Random();
    private final RSocketRequester rSocketRequester;

    public MarketDataRestController(RSocketRequester rSocketRequester) {
        this.rSocketRequester = rSocketRequester;
    }

    @GetMapping(value = "/current/{stock}")
    public Publisher<MarketData> current(@PathVariable("stock") String stock) {
        logger.info("Get REST call for stock : "+stock);
        return rSocketRequester.route("currentMarketData")
                               .data(new MarketDataRequest(stock))
                               .retrieveMono(MarketData.class);
    }
}

When i RUN server and client I get incomprehensible behavior to me. By SOAP UI I make single request in 2 threads.

In client log I get:

2021-09-01 11:30:14,614 INFO [reactor-http-nio-2] com.baeldung.spring.rsocket.client.MarketDataRestController: Get REST call for stock : pko
2021-09-01 11:30:14,691 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.client.MarketDataRestController: Get REST call for stock : pko

In server I get logs like:

Log from first shot:

// get data from client
2021-09-01 11:30:14,843 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRSocketController: Getting data for: MarketDataRequest(stock=pko)
// Log that Contoller thread go forward after call repository
2021-09-01 11:30:14,844 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRSocketController: Controller thread move forward: MarketDataRequest(stock=pko)
// Log that repository sleep thread
2021-09-01 11:30:14,862 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRepository: Repository thread go speel ZzzZZ
// Repository finish work
2021-09-01 11:30:24,863 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRepository: Repository thread move forward

Server is procesing only single call and just wait when repository finish job. Then process next request in similar way:

2021-09-01 11:30:24,874 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRSocketController: Getting data for: MarketDataRequest(stock=pko)
2021-09-01 11:30:24,874 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRSocketController: Controller thread move forward: MarketDataRequest(stock=pko)
2021-09-01 11:30:24,874 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRepository: Repository thread go speel ZzzZZ
2021-09-01 11:30:34,876 INFO [reactor-http-nio-3] com.baeldung.spring.rsocket.server.MarketDataRepository: Repository thread move forward

I don't understand why the server is processing calls one by one. Maybe there is some problem in code or maybe I'm not understand something right. Thank you in advance.

ANSWER

Answered 2021-Sep-01 at 16:38

In Reactor, by default, everything is running on the main thread. Calling Thread.sleep the main thread is blocking and the application freezes. if you would like to simulate a long-running operation you could use the delayElements operator:

.delayElements(Duration.ofSeconds(10));

Note: Reactor BlockHound detects and reports such blocking calls.

Source https://stackoverflow.com/questions/69011613

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install socket.core

You can download it from GitHub.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with socket.core
Consider Popular TCP Libraries
Try Top Libraries by fengma312
Compare TCP Libraries with Highest Support
Compare TCP Libraries with Highest Quality
Compare TCP Libraries with Highest Security
Compare TCP Libraries with Permissive License
Compare TCP Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.