Are C sockets and socket.io/Websockets from React compatible? - c

So I've created a simple chatserver / chatclient in C. The chatclient reads from stdin and outputs to stdout. The goal is to adapt this to a frontend web UI. I was thinking of using React and it seems like the most commonly used socket libraries are socket.io or Websockets.
So my big question is: can I replace my chatclient I've built in C with a React chatclient that uses socket.io or Websockets to connect to my chatserver in C?
Are the two sockets compatible?

The answer is both "Yes" and "No", but the answer given by justcivah probably should have been "No", since it lacks vital information (edit: the referenced answer was deleted)...
The reason is that WebSockets is a protocol, so your server needs to understand that specific protocol.
The WebSockets protocol usually runs as an additional layer over TCP/IP sockets (which is the only layer you probably have on your C chatserver), and it includes additional ("header") data before the "message" (payload). WebSockets also require an HTTP based handshake (though other possible handshakes might be added in the future).
There are a number of different WebSocket libraries in C that could help you implement the WebSockets protocol in your C chatserver - just search for C WebSocket Framework or something like that.

Related

Stomp protocol in Codename One

I don’t feel comfortable using WebSocket with Codename One and Spring Boot. Maybe my “error” was the implementation of one my own communication protocol over websocket, featuring ack and other hard to implements things. My protocol have issues that I wasn’t able to fix... I spent a lot of time creating it, but there are too much complexities for me.
Today I discovered that I tried to reinvent the wheel... since there are protocols over websocket like STUMP:
https://www.toptal.com/java/stomp-spring-boot-websocket
STOMP is a simple text-based messaging protocol that was initially created for scripting languages such as Ruby, Python, and Perl to connect to enterprise message brokers. Thanks to STOMP, clients and brokers developed in different languages can send and receive messages to and from each other. The WebSocket protocol is sometimes called TCP for Web. Analogically, STOMP is called HTTP for Web. It defines a handful of frame types that are mapped onto WebSockets frames, e.g., CONNECT, SUBSCRIBE, UNSUBSCRIBE, ACK, or SEND. On one hand, these commands are very handy to manage communication while, on the other, they allow us to implement solutions with more sophisticated features like message acknowledgment.
Is there any Stomp implementation for Codename One? Or the implementation of any other protocol over websocket? Thank you
I'm afraid not at this time. I also tried looking for implementations in Java but couldn't find any. It would actually be really nice if we had something like that.
I found an implementation for Android but I didn't get the chance to look at the complexity of porting it to Codename One.

Creating a basic protocol stack

I want to write an Application layer protocol that uses TCP to return certain ASCII Text when a GET request is sent. I read the first HTTP specification and the SMTP specification but am still unclear on how to write the protocol connecting the two computers itself. How could I write this in C? Are there any tutorials or examples I could look at?
The heart of any communication protocol is the interface control document(ICD), which will describe the message structures that are allowed, like what is the size of your header, data, crc field etc. It is from this document you create the C structures. Usually people use bit fields to encapsulate the message fields appropriately. When you use existing communication methods, for example Ethernet you have the TCP or UDP sockets to send and receive the data. You can encode your messages in them. If you want to develop a new communication protocol then you have to make a logic of your own and embed it over existing media and proceed.
You're asking two questions. Your first question is "How can I create a new communications protocol", and your second question is "How can I implement this in C".
These are both far too generic to be good questions per the charter of this forum.
The answer to "How can I create a new communications protocol" is, as millimoose already pointed out, simple: A protocol is a document specifying the set of rules for how entities can communicate. Decide what a conversation should look like, starting from the "hello" or equivalent, specifying every possible request and every possible response, and every possible error response, through to how to say goodbye (and how to deal with a connection that gets dropped with saying goodbye), and write that all down. The SMTP protocol is actually a fairly good example of exactly that, in fact. (A TCP-based internet protocol will also typically specify a default TCP port to operate the protocol over.)
The answer to "How can I implement this in C", now that you have a fully specified protocol, is the same as the answer to "How can I implement this in Java", "How can I implement this in REBOL", or "How can I implement this in TCL": Write a basic server app that speaks the server half of the protocol and a basic client app that speaks the client half of the protocol.
(Of course, you might actually have been intending to ask "Regardless of the specific protocol, how can I write in C a server and client that communicate with each other?". This is also an excessively generic question, which can be answered through judicious searching on google.)
In practice, it is much better to use an existing TCP stack (e.g. tcp(7) socket implementation, at least on Linux), then use some HTTP server library above it, like e.g. libonion. Reinventing your TCP stack and your HTTP server layer would take you more than a year of work.

Any HTTP library in C that allows direct communication with the server?

Do you know of any HTTP client library in C (with SSL support) that also allows direct communication with the remote server?
I have a client-server application where the client uses HTTP to start a session in the server and then tells the server to switch the connection from HTTP to a different protocol. All communication is encapsulated in SSL. It is written in Perl and works well, but I'm looking into implementing the client in C.
I know libcurl gives you access to the underlaying socket but it's not enough because of the SSL requirement.
Notice that libcurl doesn't do the SSL part by itself, it uses OpenSSL. So, if you can get the socket handle from libcurl after the first HTTP interactions, AND the session key it uses (some spelunking required) you can go on directly with OpenSSL from that point.
I think that you must be looking for this otherwise you must have to write it yourself, like this
Sounds like you want Web Sockets. Don't know if there's a C library available though. I would assume there is, if you dig.

HTML5 Web socket Handshaking

I'm sort of new to web programming, but I wanted to write a HTML interface for a embedded device (coded in C) that I am developing. I've already implemented a stream server (a la beej's socket server example) and a java client, but I'm interested in implementing a HTML5 Socket interface instead.
I am having some trouble with the handshaking (in so much as the server accepts the connection but the web page does not), and was wondering if there was a specification available somewhere on line. The w3c spec seems to only describe the API (as far as I can tell) and not the details of the handshake. I'm not looking for a fully written example (I can do that!) just a reference for the handshaking that is better than the Wikipedia entry (or an explanation of why that entry should be enough to fully understand the spec).
If anyone could help me get it up and running I will happily package it all in a library and demo and put it up on google code.
Thanks... and please let me know if you need more info to help answer the quesiton!
It looks like this is the specifiction here. I'm not much of a web prgrammer myself either. However, based on my limited understanding, I'm curious about whether you really need to implement WebSockets. Could you just using a series of HTTP messages instead?
Did you check your code against existing servers :
http://www.codeproject.com/KB/webservices/c_sharp_web_socket_server.aspx?msg=3364691 ?
with updated to last websocket specification here :
http://nugget.codeplex.com/
Another one here :
or http://superwebsocket.codeplex.com/
Not much difference betwee c# eand C in this case...

What is the format for the headers and message body of a TIBCO-RV packet?

I need to decode a packet sent using TIBCO-RV and pull fields out of the header and skip over the message body. I have not been able to any examples or documentation. Does anybody know of any open source applications that might do this or if there is a Wireshark dissector out there somewhere?
Maybe you should try applying for a license and getting the official documentation. According to Wikipedia:
TIBCO provides messaging APIs in C,
C++, Java, Visual BASIC , Perl and
.NET to receive data feeds on MS Excel
spreadsheets and other applications of
choice.
Failing that, you could perhaps dive into the TIBCO:RV Perl module.
The methods which TibcoRV implements reliable mutli-cast are propriety, but one would assume easy to reverse engineer. I don't believe any of the official documentation goes into detail on the packet level detail. It's quite easy to get the data out if you have the API.
Several things come to mind:
Is the client on your machine running? This is required in order to create the multicast subscription (unless you are using broadcast mode). Otherwise, you need to have some client subscribe to the multicast channel, or your switch shouldn't forward the traffic.
Generally, you will have a single rrd running locally. You have TCP traffic between the RRD and your app. You can use an app like socketsniff to view the traffic between the two.

Resources