c# - I have a time clock connected to my local network and I have a Windows server on localweb and I can't get the clock
- c - Solaris 10 make Error code 1 Fatal Error when trying to build python 2.7.16 - Stack Overflow 推荐度:
- javascript - How to dismiss a phonegap notification programmatically - Stack Overflow 推荐度:
- javascript - Get the JSON objects that are not present in another array - Stack Overflow 推荐度:
- javascript - VS 2015 Angular 2 import modules cannot be resolved - Stack Overflow 推荐度:
- javascript - Type 'undefined' is not assignable to type 'menuItemProps[]' - Stack Overflow 推荐度:
- 相关推荐
I am developing a .NET service that acts as a server listening on port 3000. The service is implemented and running correctly in a local environment. However, I am facing difficulties getting the time clock device on my local network to communicate with the server on port 3000.
The configuration on the time clock device is straightforward and done through a panel. In this panel, I provide the host IP, the communication port, the communication mode, and the operation mode of the time clock (client or server). In my case, I have configured the time clock to operate as a client, so it periodically attempts to communicate with the host on the configured port.
When I run the service locally, everything works perfectly. However, when deploying it to a production environment or a network setup, the communication fails. I have already opened the necessary firewall rules for both inbound and outbound traffic on port 3000, but I still cannot get it to work.
I would appreciate any assistance in identifying what might be missing or any additional configurations I should check. Thank you in advance!
In the code, I use a TcpListener configured to listen for connections on port 3000. I also implemented a log file to record communication events. When testing locally using PowerShell with the command:
Test-NetConnection -ComputerName 191...175 -Port 3000
or using Telnet, the communication works as expected, and the log records the events correctly.
Here block the code
For creating the program:
1st step: Open Visual Studio
2nd step: Select template Worker Service
3rd step: replace the Worker.cs class code with:
using System.Net.Sockets;
using System.Net;
namespace service
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;
public Worker(ILogger<Worker> logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
TcpListener listener = new(IPAddress.Any, 3000);
listener.Start();
string path = @"C:\LogsService";
string filePath = Path.Combine(path, "log.txt");
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
using (var fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
using (var write = new StreamWriter(fileStream))
{
await write.WriteLineAsync($"Worker running");
}
}
while (!stoppingToken.IsCancellationRequested)
{
var client = await listener.AcceptTcpClientAsync();
try
{
using (var fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
using(var write = new StreamWriter(fileStream))
{
await write.WriteLineAsync($"Worker running at:{client.Client.RemoteEndPoint?.ToString()}");
}
}
}
catch (Exception)
{
throw;
}
}
try
{
using (var fileStream = new FileStream(Path.Combine(path, "exit.txt"), FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
using (var write = new StreamWriter(fileStream))
{
await write.WriteLineAsync($"Exit: {stoppingToken.IsCancellationRequested.ToString()}");
}
}
}
catch (Exception)
{
throw;
}
}
}
}
Here settings time clock device
- 鲍尔默安抚硬件伙伴:Surface只是一个参考设计
- windows 10 - Gamemaker Mobile device Inconsistent Drag Speed Across Different Operating Systems (Win7 vs. Win10) - Stack Overflo
- python - DeltaTable map type - Stack Overflow
- reactjs - Why can't AWS Amplify find my components from a working version of my React App? - Stack Overflow
- macos - Can't access UI "section" in AppleScript - Stack Overflow
- Fixing Crashing on load of 3D model on React Native - Stack Overflow
- bitcoin - Problem with sign PSBT.Error sign transaction - Stack Overflow
- typescript - Issues with generic type narrowing on merged records - Stack Overflow
- Flutter upload document : file key is missing in payload - Stack Overflow
- javascript - PHP Cross-Domain POST Request - Session Cookie Not Persisting After Redirect - Stack Overflow
- node.js - Electron app with CRA failing child process creation - Stack Overflow
- How to programmatically trigger "Next desktop background" in Windows using C#? - Stack Overflow
- flutter - Retrieving tokens from aad_b2c_webview - Stack Overflow
- kotlin - Android Studio Code Completion not working in test folder in all projects - Stack Overflow
- javascript - Turning a horizontal scroll image gallery for desktop (using vertical scroll gesture) into a vertical scroll galler
- I can't receive messages through my webhook with Whatsapp Cloud API - Stack Overflow
- Clicking on Android Studio on Mac makes Chrome window disaapear - Stack Overflow