Is it possible to send various things like messages and files over single TCP connection at the same time?
For example, I want to send text commands during file sending. Is it possible without slowing down connection too much? If this is possible, how would I achieve this? Do I need to send it in packets with description ID of each packet?
Or is it best to open two separate connections?
See How the "OK" message looks like? for a discussion of how to "frame" messages/whatever over a TCP connection.
Related
as stated above, im trying to checking connection between server and client, without using ping, or some packet that will send every second.
i already try ping method, but this method will cause flooding, and i already try tcp method that act like icmp, the tcp packet will send tcp packet every second, to make sure the connection betweet sever and client still on, but this doesnt solve the flooding problem.
do you guys have any idea how to do this, without causing flooding?
all i need is server only send like 3 way handshake, and the connection built, and when the client off, something will trigger the server, and tell that server that, this client in particular are offline.
in simple, how to monitor client and server connectoin without sending multiple packet?
thank you
Say some link halfway between the client and server stops passing traffic. It may or may not still be possible for the client and server to communicate, depending on whether there are alternate links. But there is no way to tell whether or not that communication is possible without doing something active. There is no passive way to tell whether or not a link failure has made a connection usable or unusable.
There is, in general, no easier or more efficient way to tell whether or not communication is possible than attempting that communication and seeing whether or not it works.
I know UDP is not a two-way communication between client & server. However, if I send a packet to clients from a server, how can I know that my packet reach it's destination?
The only way to be sure that the data you've send are received (and processed) by the server application is to let the server application explicitly acknowledge the data in a reply.
Note that contrary to a comment to your question it will not help to use TCP instead of UDP to get a more reliable transport: while your OS kernel will does its best to deliver data with TCP (instead of just trying once with UDP) it can neither guarantee the delivery (since connectivity might break) nor does it care if the server application itself has read and maybe also processed the data. The only way to know that the application has successfully read the data is to let the application itself say so.
Web games are forced to use tcp.
But with real time constraints tcp head of line blocking behavior is absurd when you don't care about old packets.
While I'm aware that there's definitely nothing that we can do on the client side, I'm wondering if there is a solution on the server side.
Indeed, on the server you get packets in order and miserably wait if misbehaving packet t+42 has been lost even though packets t+43, t+44 can already be nicely waiting in your receive buffer.
Since we are talking about local data, technically it should be possible to retrieve it..
So does anyone have an idea on how to perform that feat?
How to save this precious data from these pesky kernel space daemons?
TCP guarantees that the data arrives in order and re-transmits lost packets. TCP Man Page
Given this, there is only one way to achieve the results you want given your stated constraints, and that is to hack the TCP protocol at the server side (assuming you cannot control the Client WebSocket behavior). The simplest, relative term, would be to open a raw socket, implement your own simple TCP handshake (Syn-Ack when client Syns), then read and write from the socket managing your own TCP headers. Your custom implementation would need to keep track of received sequence numbers and acknowledge all of those you want the client to forget about.
You might be able to reduce effort by making this program a proxy to your original.
Example of TCP raw socket here.
I'm implementing a TCP stack, and have encountered an issue with half-closed connections.
My implementation acts as the server side. A client establishes a connection, then sends some data, and then sends a "FIN" message. The server then acknowledges the data from the client, sends some data of its own, and only then closes its half of the connection (sends "FIN").
The problem is that the client does not acknowledge the data sent by the server on the half-closed connection, nor its final "FIN" message. According to netstat, the client is in state FIN_WAIT2. In an identical scenario in which the server does not send any data, things go smoothly.
The client in question is netcat, so I assume the problem is on my end :)
A screen shot is available here.
The actual PCAP file is available here.
My question is, generally, should I expect ACKS for data sent on a half-closed connection; and, particularly, what am I doing wrong in the example above.
Any help would be much appreciated!
Maybe the server should send ACK=2561 instead of 2562 in FIN/ACK?
FIN-WAIT-2 means it saw the ACK, so the sequence number must be correct, but it also means it didn't see the FIN in the same segment. If the FIN counts as 1 byte maybe the LEN should be 1?
I try to send data using UDP protocol. Is it possible to understand when UDP dont send data?
Thanks a lot.
I try to a servis which run into client. And they send their IP an port number in one second. Server listen them and if they dont send this message it understand that client is not connected. I do this but I cant understand when they dont send? Do you have any suggestion
You can check the result of writeDatagram
Sends the datagram at data of size size to the host address address at port port. Returns the number of bytes sent on success; otherwise returns -1.
Then just check the return number to make sure the number of bytes sent was what you expected
Of course it's possible, but it might be hard.
I would recommend:
Verify that you don't get errors from your calls to send data (perhaps you're specifying a bad address, or the socket is in a bad state or something).
Try sending more seldom, perhaps your packets are getting dropped by your local network stack.
Make sure you really listen properly at the receiving end, perhaps the packets make it but you fail to read them properly.
Consider firewall/NAT issues, as usual with UDP. Protocol-wise, never include connection information as application data in packets, since then it's invisible to NAT-machines.
The next step might be digging down and trying to get some feedback from the local network stack, or maybe sniffing the network to see if the packets make it some way at least.