Csocket | Asynchronous TCP socket classes | Socket library
kandi X-RAY | Csocket Summary
kandi X-RAY | Csocket Summary
Asynchronous TCP socket classes
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Csocket
Csocket Key Features
Csocket Examples and Code Snippets
Community Discussions
Trending Discussions on Csocket
QUESTION
I've come across an issue when sending an object over a local connection. The object will send the first time as expected. However variables of the object are constantly being changed therefore need to be updated when sending to the other connection. This is done through sending messages prompting the other client to listen and wait for the object being sent.
I'm aware that the java.io.ObjectOutputStream.reset() method exists but keep getting the following error:
...ANSWER
Answered 2021-May-09 at 00:53To use ObjectOutputStream#reset
you have to define your field with such type.
Not ObjectOutput
, but ObjectOutputStream
.
Like this:
QUESTION
could you please help in following. I have callback function definition in the 3rd lib header:
...ANSWER
Answered 2021-Feb-24 at 15:25First, your code with ReadTCP
function template is incorrect. SOCK_CLBK
is a type of a function pointer that has an ellipsis at the end of its argument list, which is different from int
(or any other type) that ReadTCP
has. The compiler does not fail to compile because you explicitly convert the pointer to ReadTCP
to SOCK_CLBK
, but the call fails at runtime (you either receive a random value in the int a
argument or crash).
Your second piece of code with std::bind
is also wrong because std::bind
returns a function object, not a pointer to function. The function object has operator()
, so it can be called like a function, but it cannot be converted to a function pointer (for one, because the object also contains data, like the arguments you bound).
You must define a function that accepts a variable number of arguments (i.e. has an ellipsis at the end of its argument list) and pass that function as the callback. In that function, you can process the passed arguments and possibly invoke other specialized functions in your code, like ReadTCP
.
QUESTION
I have Erlang SSL TCP socket which has a permanent TCP connection to other party, we use a protocol similar to ISO8583 protocol four first byte is a packet size which is ASCII encoded. Based on Erlang inet documentation (https://erlang.org/doc/man/inet.html) It only supports unsigned integer for packet size.
The header length can be one, two, or four bytes, and containing an unsigned integer in big-endian byte order.
right now I use gen_server handle_info, as soon as I receive a packet I read first four byte then compare it to Binary size and if the binary size is small I do nothing and put recieved binary to LastBin and wait for rest of packet and If more than one msg is in packet I call read_iso packet several times, short sample if what I do is like this:
...ANSWER
Answered 2021-Jan-07 at 05:38Question 1: Your packet protocol doesn't fit with erlang's packet protocol, so I think you need to read from the socket in raw
mode by specifying {packet, raw}
or equivalently {packet, 0}
, see https://erlang.org/doc/man/inet.html#packet.
I'm not sure how you are using handle_info()
to read from the socket. Are you setting {active, true}
so that data sent to the socket lands in the genserver's mailbox? If so, I don't think that will work because {active, true}
tells erlang to automatically read N
bytes from the socket, where N
is specfied by {packet, N}
when you open the socket. In your case, N
will be 4. Erlang then uses the integer contained in those 4 bytes, let's call it MsLen
, to read MsLen
bytes from the socket. Erlang then combines all the chunks it reads from the socket into one complete message and places the complete message in the genserver's mailbox. However, your MsLen
will be wrong because it's not an unsigned integer, rather it's an ascii encoded integer. Therefore, I think you need to open the socket in passive mode, {active, false}
, read the first four bytes using gen_tcp:recv()
, decode to get the integer length, then call gen_tcp:recv()
again to read that many bytes from the socket.
Or, you could specify {active, true}
and {packet, raw}
so that any data sent to the socket will land in the genserver's mailbox. In that case, a message will consist of whatever size chunk happened to be sent to the socket by the underlying transport mechanism. So, you would need to use a loop around a receive block to keep extracting messages from the mail box until you got enough bytes for a complete message.
Question 2: When you open a socket in active
mode, {active, true}
, erlang automatically reads N
number of bytes from the socket, where N
is specified in {packet, N}
, then erlang combines the chunks into a complete message and places the message in the process mailbox, which can only be read by a receive clause. Calling gen_tcp:recv()
reads from the socket, which is of no help in that case. See details here: Erlang client-server example using gen_tcp is not receiving anything.
Specifying {active, once}
tells erlang to open the socket with {active, true}
for one message, then the socket switches to {active, false}
or passive mode. In passive mode, a process needs to read directly from the socket by calling gen_tcp:recv()
. You can specify {active, once}
when you want to prevent a hostile actor from flooding the socket with millions of messages, which in turn would fill up the process mailbox and cause the process to crash. Will a hostile actor be able to flood the socket with millions of messages?
Question: 3 Synchronous with what? When you use !
to send a message to a genserver process, the message send is asynchronous because the process that sent the message does not wait for any type of response from the genserver process, so execution continues unabated in the sending process. With a genserver, we don't ask whether handle_call()
is asynchronous, instead we ask whether the process that calls gen_server:call()
is asynchronous with the genserver process. The process that calls gen_server:call()
stops execution and waits for a response from the genserver process, so we say that the process that called gen_server:call()
is synchronous with the genserver process.
Is a process that calls gen_tcp:send()
asynchronous with the genserver process? gen_tcp:send()
returns ok
or an error message, so it does not wait for a reply from the genserver process, so a process that calls gen_tcp:send()
is asynchronous with the genserver process.
QUESTION
I am trying to send encrypted data between a client and server. Due to the RSA encryption its in Byte array form. This means I have had to change the way I send data. I curently cant get it working, Ill leave my method (sendMessage) below which is what handles the sending of the message, If anyone could tell me what I am doing wrong that would be great :)
...ANSWER
Answered 2020-Dec-17 at 19:45Thanks for the clarification! Please see https://docs.oracle.com/javase/10/docs/api/java/io/ByteArrayOutputStream.html#write(byte%5B%5D,int,int)
The write method in ByteArrayOutputStream for byte[] needs two more arguments. Something like the following might work:
QUESTION
I am in year 13 and have decided for my computer science coursework to make a small chat program using java. I have had to learn the networking aspect from scratch and my teachers are unfamiliar with it so they struggle to answer my questions. I have a client program and a server program and they communicate via a socket I creat, my issue is I dont understand the effect the try catches are having on my code. I am really fascinated with networking and thats why I chose it knowing full well it would be a challange, Ill leave my code below and the error I am having. If you could give me any tips on how I can solve my problem and also make my code 'better' that would be absolutely fantastic. Also please take into account I have only known java for around a year now and am still a novice futher more this is my first question on stack overflow!. Many thanks!
Client Code:
...ANSWER
Answered 2020-Nov-22 at 14:22Your problem seems to not be try-catch but lack of error handling.
If we assume the commented-out code in sendMessage to be actually operational:
QUESTION
im trying to send a file from server to a client Ive got this function in my server:
...ANSWER
Answered 2020-Jun-15 at 07:43You must to allocate memory for buffer, because first parameter of fread
:
Pointer to a block of memory with a size of at least (
size*count
) bytes, converted to avoid*
.
I would recommend using std::array
to not worry about deleting memory.
QUESTION
I am trying to create some kind of screen share with python socket. The problem is that the images of my screen are very big (3,110,482 bytes) and it takes a lot of time for the socket to send them to the server. For making the sending more efficient I lowered the resolution of the images I am sending, but it is not enough. So I need to make the sending process more efficient.
Here is the function that takes images of my screen:
...ANSWER
Answered 2020-Mar-29 at 11:19So I find a solution. I compress the image with numpy
and io
like this:
QUESTION
In this code, When I tried without applying multithreading on python socket, it works perfectly fine. But after using multithreading for concurrency, the first while loop works fine, but when 2nd while loop is not running until I will close the connection, doing so, it takes 2nd while loop as 2nd thread, which doesn't complete the procedure of sending passkey to android. Here, the problem is with 2nd loop as 2nd thread. How will I do that? Any help will be appreciated!
...ANSWER
Answered 2020-Feb-11 at 06:51I solved this problem as my output will also come in the way I want.The basic idea of the solution is given below:-
QUESTION
I have a multithreaded server called server.cs and a client.cs the objective of this program is as following:
Each client program will create a connection to the server. The server will reply with a welcome message (a string). The client will send to the server a string of json format. The server will reply with the same format, but added information on secret and END status. Then, the client will send a message to the server to stop the communication and will close the connection. When all the clients have communicated, at the end there will be a client with id=-1 , that informs the server to stop. When the server receives the message from the ending client (with id = -1), it must print all collected information and the number of the communicated clients.
This biggest part is done. When i use the SequentialSimulation()
method in my client.cs and run many instances of the client.cs program the server works just fine and does what the above description said. But when i use the ConcurrentSimulation()
method in the client.cs and only run one instances of the clients.cs it crashes and gives me the following error:
ANSWER
Answered 2020-Jan-23 at 20:28You have some race conditions going on
Look at this:
QUESTION
This code downloads most of the file but not all of the file (inside a while loop) any idea what I'm doing wrong?
...ANSWER
Answered 2019-Nov-24 at 12:03Normally the recv() function does not guarantee to return the total amount of bytes you "request". The argument is just a maximum amount of bytes that you expect to receive, but the function can return less bytes than this if they are available in the buffer. Here it is an implementation from https://docs.python.org/3/howto/sockets.html
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Csocket
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page