Is it possible to use UDP with Web Sockets instead of TCP - c#

I have a C# desktop app and a C# Server console app.
The C# desktop client app uses WebSocket4Net and my C# server app uses Fleck.
Am I right in assuming that it uses TCP protocol. If so, can I get it to use UDP protocol?
The reason I asking this is because I read TCP is slower than UDP because TCP ensures order of packets.
I read this from this article:
Making Fast-Paced Multiplayer Networked Games is Hard

No, WebSockets are based on TCP which in turn is based on IP. UDP is also based on IP, but doesn't have anything to make sure the packets arrive in order or arrive at all. UDP just throws packets at a remote endpoint in the hope someone catches it. It's connectionless, so impossible to use UDP with WebSockets.

Related

UDP with SSL Stream

Hi I'm working on server/Client project with C# that uses both TCP (for logging in and other stuff) and UDP (for streaming voice ). The problem is that I need to use sslStream for UDP but as far as I know its not possible to make SSL authentication with unguaranteed protocol. So is there anyway to make the authentication using TCP then use the sslStream for UDP?
Not knowing much about C# and sslStream, but: UDP is a datagram protocol and it does not guarantee that packet delivery, order and even can cause duplicate delivery. TCP instead is a stream protocol which guaranteed delivery etc. TLS works only on top of a protocol like TCP and not on top of UDP.
For UDP you would need to use DTLS instead. According to Wikipedia the Microsoft TLS Stack SChannel support DTLS 1.0 since Windows 7 and Windows 2008 R2. But when searching for C# DTLS lots of questions show up but nothing which would indicate that there is native support for DTLS with C#. But some third party libraries show up in this search which might help with your problem.

c# windows phone 8.1 creating udp socket

I am quite new with c# and app developing. How do I establish connection and send packets via UDP. I have tried to follow
https://msdn.microsoft.com/en-us/library/windows/apps/hh202864(v=vs.105).aspx
It doesn't work as it is ment for wp8
My here is not a real answer, but a workaround.
Instead of worrying about sending values via UDP socket, I'd suggest you to use a buffer/queue and implement a REST API on the server side, sending the data via HTTP requests, which is more reliable and easier to maintain...
You, of course, would send them in a async fashion, and you would still be able to juggle them up anyway you want server side...

Receiving packets from any protocol on a raw linux socket

I would like to create an IP tunnel. For that, I create a raw socket in C# on the client and bind it to port 4999:
Socket mysock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
mysock.Bind(new IPEndPoint(IPAddress.Loopback, 4999));
mysock.Connect(new IPEndPoint(IPAddress.Loopback, 4999));
Now I can just call mysock.Receive(byte[]), and I get all the IP packets, including the IP header. For example, if I try to open a TCP connection to 127.0.0.1:4999, the C# application captures 3 packets. I can also send packets over this socket and it will work just fine.
The C# application then transfers those packets to a C++ application running on a linux machine. There, I change the sender port (that's the easy part, just write it into the TCP header) and then I would like to simply send it out and have everything else done for me, just like it works in C#. And obviously, I would also like to receive packets from the raw linux socket, so I can transfer them back to the C# application and get some communication going.
I have already implemented everything except the raw linux socket. That's my question: How can I write the above C# code in C/C++ for linux? According to raw(7), I won't get TCP or UDP packets if I just do socket(AF_INET, SOCK_RAW, IPPROTO_RAW), right?
Edit: By the way, I'm running the C# code on windows but that is not my problem.
No.
The port number should not be the TCP or UDP port number in this case.
It should be (I'm not sure) the higher-level protocol identifier (e.g. a "port number" of 6 means: TCP packets while 17 means: UDP packets). The current Linux version says the port number must be 0 for raw sockets. "root" rights are required for the application.
Differences in Windows (compared to Linux):
The Windows documentation says that raw sockets are allowed for ICMP and IGMP packets (only).
Using the winpcap library should allow a program to get raw access to an Ethernet card. However you'll also see the 14 byte Ethernet header (before the IP header) in this case and you'll receive all kinds of Ethernet packets (in a normal TCP/IP network these should be ARP, IPv4, IPv6 and STP) and not only IPv4 packets.
There is a .NET wrapper for winpcap so you should be able to use winpcap with C#, too.

Is tcp listener and tcp server same thing in c#?

What is the difference between TCP listener and TCP server? I want to communicate with some devices using TCP/IP protocol and want PC to organize the communication by using C#.
The .NET class TcpListener implements a TCP server. That’s how the two terms are related. So if you want a TCP server in your application, use the TcpListener.
Since you havent posted any specific context. i would refer you some tutorials you can use as a base for TCP communication in c#.
http://www.codeproject.com/Articles/155282/A-Complete-TCP-Server-Client-Communication-and-RMI
http://www.switchonthecode.com/tutorials/csharp-tutorial-simple-threaded-tcp-server
http://www.codeproject.com/Articles/5733/A-TCP-IP-Server-written-in-C
http://www.dreamincode.net/forums/topic/50259-tcp-client-connection/
the previous answer sites the difference.

Sending message from one PC to another PC using IP address

I want to send a message from one computer (server) to another computer (client). Both the client and server are on an internal network with different IP addresses.
How do I send the message using the IP address without using the command prompt?
You need to look at socket programming.
Here is list of good tutorials that does what you are after:
How to use Sockets in C#
TCP/IP Chat
Simple TCP/IP Chat client/server
Creating a Mutli-User TCP Chat Application
The Microsoft link (the last one) is in VB.Net, but you can use the Code Convertor tool to help convert it to C#.
Also, there is the Lidgren Network library that is very easy to use.
You need to have a look at System.Net.Sockets namespace. What you're asking is very vague and it doesn't appear that you have investigated all that well. Sockets allow you to connect to other machines (and listen for incoming connections appropriately) and pass data between the two.

Categories

Resources