Jump to content

C# receive socket

Cruiseshipfan

I have a project where I need to send data from a raspberry pi to a PC so I can use unity to display a HUD on the oculus rift though unity. I have written the server code on the Pi using C and successfully sending the data to the PC. However I am not familiar with C# and don't know what library's exist to receive sockets. So I was wondering if someone could help me out a little. Below is the code I have for the client, I just need to figure out how I can write that in C#.  

#include <stdio.h>#include <string.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#define SERVERIP "10.222.165.255" //IP address of the server.#define PORT    53123   //Port used for connection.int main () {    short   sensors[8];                 //data[0] contains the received position value.    int     dataSocket,                  //The socket to receive value.	    i;        sa.sin_family = AF_INET;    //Port value to use.    sa.sin_port = htons(PORT);    //IP address of the server.    sa.sin_addr.s_addr = inet_addr(SERVERIP);    memset(sa.sin_zero, '\0', sizeof(sa.sin_zero));   //Set up socket.   dataSocket = socket(PF_INET, SOCK_STREAM, 0);   if (dataSocket == -1) {       printf("Could not create socket!\n");    }   //Locate and connect to server.   printf("Connecting to server. Please wait.\n");   while (connect(dataSocket, (struct sockaddr*)&sa, sizeof(sa)) == -1) { }   printf("Successfully connected to server.\n");   while(1)   {      recv(dataSocket, sensors, sizeof(short)*8, 0);      // DO STUFF WITH DATA.    }   return 0;}

My PC:

Case: NZXT Phantom 420 | Motherboard: Gigabyte GA-Z77X-UD3H-WB WIFI | PSU: Corsair TX650M | CPU: Intel 3570k | CPU Cooler: Corsair H60 with Corsair SP120s in push pull | GPU: AMD 7970 GV-R797OC-3GD | RAM: 16GB Corsair Vengeance 4x4GB | SSD: Samsung 830 256GB | HDD: Seagate Barracuda 2TB
Link to comment
Share on other sites

Link to post
Share on other sites

Umm, WebSocket? I'm not sure if you want the C# one (the one I mentioned) or some higher level one.

Link to comment
Share on other sites

Link to post
Share on other sites

 

The System.Net.Sockets namespace provides multiple options for working with Sockets.

 

 

Ah thank you. Those links are very helpful. Hopefully everything goes to plan. 

My PC:

Case: NZXT Phantom 420 | Motherboard: Gigabyte GA-Z77X-UD3H-WB WIFI | PSU: Corsair TX650M | CPU: Intel 3570k | CPU Cooler: Corsair H60 with Corsair SP120s in push pull | GPU: AMD 7970 GV-R797OC-3GD | RAM: 16GB Corsair Vengeance 4x4GB | SSD: Samsung 830 256GB | HDD: Seagate Barracuda 2TB
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×