Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm creating a messaging application for andriod/ios, but I am completely new to c# and networking, I've followed the first steps of a simple socket tutorial to get me started in networking (
https://www.youtube.com/watch?v=KxdOOk6d_I0
) but I get the error:
error "CS1022: Type or namespace definition, or end-of-file expected".
I'm assuming that it has something to do with the namespace because im new to c# and don't actually understand what the namespace does, but my compiler says there are no errors (I'm using visual studio code if that makes a difference) but it may be something else.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
namespace server_test
class program
static void main(string[] args)
IPAdress ip = Dns.GetHostEntry("localhost").AdressList[0];
TcpListener server = new TcpListener(ip, 8080);
TcpClient client = default(TcpClient);
server.Start();
Console.WriteLine("server started...");
Console.ReadLine();
}catch (Exception ex)
Console.WriteLine(ex.ToString());
Console.ReadLine();
it should say server started..." or throw up an exeption but this is what im getting every time:
[Running] mono "C:\Users\Aidan\AppData\Roaming\Code\User\cs-script.user\cscs.exe" "d:!computer science!!NEA!\test stuff\networking\server_test\program.cs"
Error: Specified file could not be compiled.
csscript.CompilerException: d:!computer science!!NEA!\test stuff\networking\server_test\program.cs(7,127): error CS1513: } expected
d:!computer science!!NEA!\test stuff\networking\server_test\program.cs(37,1): error CS1022: Type or namespace definition, or end-of-file expected
at csscript.CSExecutor.ProcessCompilingResult (System.CodeDom.Compiler.CompilerResults results, System.CodeDom.Compiler.CompilerParameters compilerParams, CSScriptLibrary.ScriptParser parser, System.String scriptFileName, System.String assemblyFileName, System.String[] additionalDependencies) [0x00102] in :0
at csscript.CSExecutor.Compile (System.String scriptFileName) [0x0080d] in :0
at csscript.CSExecutor.ExecuteImpl () [0x005a1] in :0
[Done] exited with code=1 in 1.795 seconds
–
There was a typo in addresslist.
One more problem was - The main function should be spelled as "Main" with capital M.
Full program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
namespace server_test
class program
static void Main(string[] args)
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
TcpListener server = new TcpListener(ip, 8080);
TcpClient client = default(TcpClient);
server.Start();
Console.WriteLine("server started...");
Console.ReadLine();
catch (Exception ex)
Console.WriteLine(ex.ToString());
Console.ReadLine();
The error shows The file could not be compiled. So, most probably it's compiler error. I guess below if it's not a typo, the spelling of ipaddress missing a d and so thus AddressList.
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.