using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace PowerCarsMobileServer
{
class Server
{
public static int Port { get; private set; }
private static TcpListener tcpListener;
public static ServerSocket serverSocket; //problem is here
public static void Start(int _port)
{
Port = _port;
serverSocket = new ServerSocket(Port);
Console.WriteLine("Starting server...");
InitializeServerData();
tcpListener = new TcpListener(IPAddress.Any, Port);
tcpListener.Start();
Console.WriteLine($"Server started on {Port}.");
}
}
}
When creating a global port, I ran into the problem of not supporting "ServerSocket". Older articles use ServerSocket but I don't understand the problem comparing my code with theirs.
How can I fix it?
I tried to connect different references, but it doesn't work or I didn't find a good one
You are using .Net and ServerSocket is an Android class.
To setup a server socket TCP connection in .Net:
And in the AcceptCallback delegate:
And the connection is established on newSocket where you can start receiving:
The data can then be accessed from the state.byteArray in the ReceiveCallback delegate.
If the server app is listening in some remote location where the ip address is known (i.e. for all websites and server-side services on Azure or AWS) all external clients from any location on the internet will be able to initiate a connection for two-way communications.