c#


NetworkStream write() with event name


I have a simple TCP server written in C#, pinging out data at a specified interval and receiving the data I have a NodeJS app.
I'm current sending the data from a NetworkStream like so:
private NetworkStream nwStream;
nwStream = clientMachine.GetStream();
nwStream.Write(buffer, 0, buffer.Length); // Inside a loop
And receiving it in NodeJS like:
client.on('data', (data) => {
Is there any way to emit a different event, other than data from my C# TCP server? Using Socket.io I can socket.emit('customEvent', someData) and receive it like socket.on('customEvent', receivedData) but I'm unsure if I can achieve this in C#.
I'm not working with Socket.io, the above is just an example of the behaviour I'd like to achieve.
If you're using raw sockets at both ends, you'll just have to design your own protocol that embeds a name into each logical frame... TCP sockets themselves don't have any such mechanism, nor do raw packets.
A typical / simple way of doing this might be something like:
{Event name, UTF8}\r\n{length, 4 bytes little endian integer}{payload, length bytes}
If your event name might include newline/linefeed, then you'd need to use the payload length/payload approach for the event name, too.
Socket.IO has it's own network protocol specified here. The encodeAsString(obj) function in 'socket.io-parser' may be what you're looking for.

Related Links

C# System.IndexOutOfRangeException: Index was outside the bounds of the array [duplicate]
How to create a function log file using C#?
Incorrect syntax near '00' on manual migration
MySql unknown column in field list error
Assignment of new value to immutable value structs in C++/CLI
How to read XML with name/value pair in c#? [duplicate]
Model binding and ViewBag in asp.net core mvc
Updating a view after button click in ASP.NET MVC
Test for .Net framework installation
Display all strings from array in datatable
EF core NullReferenceException accessing related entity
Replace specific image on specific page in PDF using iTextSharp and C#
how to put a repeater buttons in a row on asp c#
Two Columns Grouping Sum
Show differences between two DataTables in C# with LINQ
Bluetooth baseadapter and listview in C#

Categories

HOME
autohotkey
gcc
grizzly
ftp
ide
typo3
cors
customization
packet
glsl
nagios
where
css-selectors
kendo-asp.net-mvc
jquery-select2
velocity
captcha
drush
brightway
simd
printf
gomobile
fastboot
procedural-generation
ithit-webdav-server
inspec
windows-mobile
ballerinalang
proof-general
angular-schema-form
hierarchy
folder
vtd-xml
opencsv
storefront
rtos
matlab-compiler
incapsula
certbot
ansible-inventory
ragel
yelp
libconfig
android-graphview
uitextview
amazon-rds-aurora
ack
qtwebkit
jenkins-2
g77
ng-class
noise
openxava
openidm
vertex
aot
suitesparse
therubyracer
sqlproj
blitz3d
addressbook
easy-thumbnails
boost-range
qtruby
transaction-isolation
archiva
treelist
salesforce-service-cloud
factorization
hana-sql-script
computability
producer-consumer
uinavigationitem
bootstrap-tabs
winforms-interop
p4python
playn
web-standards
minko
skview
autopep8
ios-enterprise
im4java
smartxls
cvi
netbeans-plugins
xcode6.1-gm-seed
thucydides
tlbimp
select2-rails
coinbase-php
bho
generator-expression
custom-cursor
ios6-maps
filedialog
nsscrollview
optimistic-concurrency
facebook-winjs-sdk
nsundomanager
code-organization
httppostedfilebase
openwrap
peoplepicker
overlays
lightopenid
norton
llblgen
asp.net-1.1
hotfix

Resources

Encrypt Message