Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions NetInput.Capture/NetInput.Capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void SendResetControllers()
printf("Failed to send reset message.\n");
}

void PollControllers()
void PollControllers()
{
XINPUT_STATE state;
for (uint32_t i = 0u; i < XUSER_MAX_COUNT; i++)
Expand All @@ -49,17 +49,47 @@ void PollControllers()
int main()
{
std::string ip;
std::int16_t port = 4313;

std::ifstream input_file("target.txt");
if (input_file.is_open())
{
printf("Reading ip from target.txt.\n");
ip = std::string((std::istreambuf_iterator<char>(input_file)), std::istreambuf_iterator<char>());
std::string line;

int index = 0;
while (!input_file.eof()) {
getline(input_file, line);

switch (index)
{
case 0:
if (inet_pton(AF_INET, line.c_str(), &(addr.sin_addr)) != 1)
{
std::cout << line << " is not a valid ip, please correct target.txt\n";
return -1;
}

ip = line;
break;
case 1:
try
{
port = std::stoi(line);
if (port <= 0)
port = 4313;
}
catch (...)
{
std::cout << line << " is not a valid Port number, using default value(4313) correct target.txt if your intent was to use another Port number\n";
port = 4313;
}
break;
default:
break;
}

if (inet_pton(AF_INET, ip.c_str(), &(addr.sin_addr)) != 1)
{
std::cout << ip << " is not a valid ip, please correct target.txt\n";
return -1;
index++;
}
}

Expand All @@ -69,7 +99,7 @@ int main()
{
printf("Please enter the IP of the target computer.\n");

std::cin >> ip;
std::cin >> ip;
if (inet_pton(AF_INET, ip.c_str(), &(addr.sin_addr)) == 1)
break;

Expand All @@ -85,7 +115,7 @@ int main()

WSADATA wsaData;
int wsaStartupResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (wsaStartupResult != 0)
if (wsaStartupResult != 0)
{
printf("WSAStartup failed with error code 0x%08X.\n", wsaStartupResult);
return -2;
Expand All @@ -98,8 +128,9 @@ int main()
return -3;
}

printf("Port is %d.\n", port);
addr.sin_family = AF_INET;
addr.sin_port = htons(4313);
addr.sin_port = htons(port);

printf("Sending reset...\n");
SendResetControllers();
Expand Down
40 changes: 36 additions & 4 deletions NetInput.Player/NetInput.Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <iostream>
#include <stdint.h>
#include <string>
#include <stdint.h>
#include <fstream>

SOCKET sock;
PVIGEM_TARGET pads[XUSER_MAX_COUNT];
Expand Down Expand Up @@ -49,18 +52,45 @@ int main()
return -2;
}

//Read target port from file
int targetPort = 4313;
std::ifstream input_file("port.txt");
if (input_file.is_open()) {
printf("Reading port from port.txt\n");
std::string line;
getline(input_file, line);
try
{
targetPort = std::stoi(line);
if (targetPort <= 0)
targetPort = 4313;
}
catch (...)
{
std::cout << line << " is not a valid Port number, using default value(4313) correct port.txt if your intent was to use another Port number\n";
targetPort = 4313;
}
}

//Bind socket to port.
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(4313);
addr.sin_port = htons(targetPort);
inet_pton(AF_INET, "0.0.0.0", &(addr.sin_addr));

if (bind(sock, (const sockaddr*)&addr, sizeof(addr)) == SOCKET_ERROR)
int bindResult = bind(sock, (const sockaddr*)&addr, sizeof(addr));

if (bindResult == SOCKET_ERROR)
{
printf("Failed to bind to 0.0.0.0:4313.");
printf("Failed to bind to 0.0.0.0:%d\n", targetPort);
closesocket(sock);
WSACleanup();
return -3;
}
else
{
printf("Binded to 0.0.0.0:%d\n", targetPort);
}

printf("Done.\n");

Expand All @@ -87,6 +117,8 @@ int main()

printf("Done.\n");

printf("Press ESC to exit at any moment...\n");

printf("Waiting for data...\n");

struct sockaddr_in clientAddr;
Expand Down Expand Up @@ -135,7 +167,7 @@ int main()
ResetGamepads();
vigem_disconnect(client);
vigem_free(client);
closesocket(sock);
int closeSockedResult = closesocket(sock);
WSACleanup();
CoUninitialize();
return 0;
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@

NetInput is an easy way to send gamepad input over the network with low latency. It supports up to 4 gamepads at a time. The program assumes a single source and a single receiver. Ideal in a setup where you have a display out but no way to access USB to plug in a gamepad.

The program will ask for your target computer when starting up, if you do not want to be prompted every time please create a file called "target.txt" with the target computer ip as its contents.
The Capture program will ask for your target computer when starting up, if you do not want to be prompted every time please create a file called "target.txt" with the target computer ip and the port number as its contents.

For example:
```
192.168.1.31
4313
```

For the Player, to select a custom port is neccesary to create a file called "port.txt" with the port number.
For example:
```
4313
```


## Local Setup Guide

1. Install the requirements
2. Run the Player on the computer you would like to send the gamepad input to
2. Run the Player on the computer you would like to send the gamepad input to, if you want a custom Port number, create the "port.txt" and define the port.
3. Figure out the IP address of the computer running the player (open up terminal and type ipconfig)
4. Create a file called target.txt in the same folder as the Capture program on the computer you would like to capture the gamepad input from and insert add the IP of the computer running the Player in that file
4. Create a file called target.txt in the same folder as the Capture program on the computer you would like to capture the gamepad input from and insert add the IP of the computer running the Player in that file and the Port number
5. Run the Capture program on the computer you would like to game the gamepad input from
6. Enjoy!

## Over The Internet Setup Guide

1. Install the requirements
2. Run the Player on the computer you would like to send the gamepad input to
3. Figure out the remote IP address of the computer running the player (https://www.whatismyip.com/) and forward the required port (UDP 4313) on your router
4. Create a file called target.txt in the same folder as the Capture program on the computer you would like to capture the gamepad input from and insert add the IP of the computer running the Player in that file
2. Run the Player on the computer you would like to send the gamepad input to, if you want a custom Port number, create the "port.txt" and define the port.
3. Figure out the remote IP address of the computer running the player (https://www.whatismyip.com/) and forward the required port (UDP default:4313) on your router
4. Create a file called target.txt in the same folder as the Capture program on the computer you would like to capture the gamepad input from and insert add the IP of the computer running the Player in that file and the Port number
5. Run the Capture program on the computer you would like to game the gamepad input from
6. Enjoy!

Expand Down