I'm new to QWebsocket. I have created two applications, which use QWebsocket communication. Does anyone know if it is possible to capture the messages sent from webClient to webServer by another application on the same port? However, there is no way to change these 2 applications which communicate via web socket.
no, you cannot start a second server.
// setup the QWebSocketServer
m_server = new QWebSocketServer("WebSocket app", QWebSocketServer::NonSecureMode, this);
if (!m_server->listen(QHostAddress::LocalHost, 12345)) {
qFatal("Failed to open web socket server, probabaly caused by an existing instance!");
return;
}
Related
I have a server application, part of its code like this:
socket = socket(...); // create a socket
setsockopt(RE_USEADDR); // set the socket option RE_USEADDR
bind(socket, 127.0.0.1, 8080); // bind the socket to the IP address and Port
listen(); // listen
Here is the question:
I launch the server application twice, on the same machine, same user.
Both of them can work well.
Launch the client application, which connects to 127.0.0.1:8080
Send some contents to the server.
However only one of the server application can receive the message from client.
Is there anyway to make sure the two server applications all receive the message from client.
If there is, please explain how and why in TCP and UDP.
Thank you very much
I'm writing a simple server-client using MIDL and RPC to allow file transferring.
It works when endpoint is hard coded as follow:
server side
status = RpcServerUseProtseqEp(
reinterpret_cast<unsigned char*>("ncacn_ip_tcp"),
RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
reinterpret_cast<unsigned char*>("8888"),
NULL);
Client Side
status = RpcStringBindingCompose(NULL,
"ncacn_ip_tcp",
(RPC_CSTR)"127.0.0.1",
"8888",
NULL,
NULL);
I'm wondering if multiple clients are able to connect to one server when endpoint is hard coded? As we know that in socket programming using TCP protocol, two application cannot connect to a single port at one time. However, the MSDN reference says that RPC server process uses a first-in, first-out call queue to handle requests.
If it is unable to receive multiple requests from clients, is there a way to set an endpoint pool? Thank you.
You're confusing the terminology here.
The server is listening on a TCP port. That means it binds to the port and starts the accept loop on it. Every time that a new client connects to this port, the accept function establishes a TCP connection with that client, and goes back to listening on the port.
The server application is either a multi-threaded or an asynchronous application that handles multiple actions simultaneously: listening for new clients, communicating with each connected client and performing the actual work.
A typical RPC server would look something like
status = RpcServerUseProtseqEp(pszProtocolSequence,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
pszEndpoint,
pszSecurity);
if (status) exit(status);
status = RpcServerRegisterIf(my_rpc_interface_spec,
NULL,
NULL);
if (status) exit(status);
status = RpcServerListen(cMinCalls,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
0);
if (status) exit(status);
The RpcServerListen call would block forever, start cMinCalls worker threads and perform the accept loop, accepting the connections and handling the requests in up to cMinCalls parallel threads.
Is there any server-client like inter-process-communication method which allows:
the server to reliably get the process-ID of a connected client
any client-application to connect to the server
works in C/C++
Optionally: Works also on Linux
Since your server runs with root rights, you can work with task_for_pid() and a two way connection. First, the client will send its pid to the server via some special bootstrap port on the server, the server will then resolve the pid via task_for_pid to a task port and then use mach_port_insert_right to insert a send right to a new port into the client. The new port is then exclusively to the client and you know what security level the client has.
I'm currently working on a C++ application that communicates with my browser using WebSockets. The connection is only local, there won't ever be any non-local socket.
Currently my C++ code looks like that (just for an example):
while (true) {
WebSocket *socket = server->accept () ;
socket->read (buffer, 256) ;
}
And my javascript code:
var socket = new WebSocket ("ws://localhost:4564") ;
socket.onopen = function () {
socket.send("Hello my name is Holt!");
} ;
As you can see, I'm waiting for a packet that should be sent as soon as the connection is openned. So I got 2 questions:
First, are there any way to send this information directly inside the connection? (I think no, so it's why my second question comes for...)?
Second, knowing that the connection is local, is that possible that the server accept the socket without being able to retrieve the packet after?
To add a bit more information, the current C++ application is based on Qt 5.3 with the QtWebSockets module and the javascript code is a Google Chrome extension that will run a script on specific websites.
Thanks for you help!
After you establish websocket connection between client and server, in client, when connection is alive, you can call socket.send() when you want to send data to server.
Even connection local, server is still need wait and receive data, which is a full TCP/IP data transfer process.
I'm trying to code a simple actionscript tcp client, which is to send data to a c++ tcp server. I'm new to actionscript and I'm using sample code from adobe (see link below) for the client. I am able to make a connection and send data, but the data is only available at the server when the object is unloaded at the client side (hence closing the socket I guess). I tried using a c++ client, and the data is immediately available at the server, so I must be missing something on the client side. Maybe I need to append some kind of termination/marker sequence?
Actionscript code sending data over tcp:
private function tcpConnect():void
{
var customSocket:CustomSocket = new CustomSocket("127.0.0.1", 5331);
customSocket.timeout = 100;
socketWrite(customSocket, 53);
socketWrite(customSocket, 54);
socketWrite(customSocket, 55);
socketWrite(customSocket, 56);
}
private function socketWrite(sock:CustomSocket, b:int):void
{
sock.writeByte(b);
sock.writeByte(0);
sock.flush();
}
C++ tcp server: http://msdn.microsoft.com/en-us/library/windows/desktop/ms737593(v=vs.85).aspx
Actionscript tcp client: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html#includeExamplesSummary
Right after connection to the server the client socket will send a request for the crossdomain file, it will look like this
<policy-file-request/>
You probably have seen this in the server logs
At this time the server should send the file back via the socket connection.
Once the client gets the file it will probably close the connection.
Now you need to restart the connection and send all your data without hinderance.