Added solution files
This commit is contained in:
parent
49a8284e44
commit
212d99d36c
120
TCPServerLWCore/Class1.cs
Normal file
120
TCPServerLWCore/Class1.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace TCPServerLWCore
|
||||
{
|
||||
public class Server
|
||||
{
|
||||
public IPAddress[] ipAddress;
|
||||
public IPEndPoint ipEnd;
|
||||
public Socket sock;
|
||||
public TcpListener tcpHandler;
|
||||
public bool isActive = true;
|
||||
public int portNumber = 65535;
|
||||
|
||||
public void initServer()
|
||||
{
|
||||
ipAddress = new IPAddress[1];
|
||||
ipAddress[0] = IPAddress.Parse("192.168.1.22");
|
||||
tcpHandler = new TcpListener(ipAddress[0], portNumber);
|
||||
tcpHandler.Start();
|
||||
while (isActive)
|
||||
{
|
||||
TcpClient client = tcpHandler.AcceptTcpClient();
|
||||
ServerObjectHandler handler = new ServerObjectHandler(client, this);
|
||||
Thread thread = new Thread(new ThreadStart(handler.process));
|
||||
thread.Start();
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
class ServerObjectHandler
|
||||
{
|
||||
public string filePath = "\\log\\log.csv";
|
||||
public Stream inputStream;
|
||||
public TcpClient socket;
|
||||
public Server srv;
|
||||
public ServerObjectHandler(TcpClient s, Server srv)
|
||||
{
|
||||
this.socket = s;
|
||||
this.srv = srv;
|
||||
}
|
||||
public void process() // Recieves an input stream. Data from the stream is sorted by bytes and needs to occur
|
||||
{
|
||||
Console.WriteLine("Connection Recieved");
|
||||
inputStream = new BufferedStream(socket.GetStream());
|
||||
StreamReader reader = new StreamReader(inputStream);
|
||||
MemoryStream ReadStream = new MemoryStream();
|
||||
byte[] buffer = new byte[1];
|
||||
int i = 0;
|
||||
int dataRead;
|
||||
char[] streamArray = new char[1];
|
||||
try
|
||||
{
|
||||
while((dataRead = inputStream.Read(buffer,0,buffer.Length)) > 0)
|
||||
{
|
||||
ReadStream.Write(buffer, 0, dataRead);
|
||||
}
|
||||
byte[] result = ReadStream.ToArray();
|
||||
streamArray = Encoding.ASCII.GetChars(result);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Console.WriteLine("End of stream");
|
||||
}
|
||||
Console.Write(String.Concat(streamArray) + Environment.NewLine);
|
||||
if(String.Concat(streamArray) == "")
|
||||
{
|
||||
|
||||
}
|
||||
string[] tempSegments = string.Concat(streamArray).Split('/');
|
||||
Array.Resize(ref tempSegments, tempSegments.Length - 1);
|
||||
string finalString = "";
|
||||
foreach(string s in tempSegments)
|
||||
{
|
||||
string temp = (s.Split('|')[2]).Replace("/", "");
|
||||
string humidty = s.Split('|')[1];
|
||||
finalString += temp + "," + humidty + Environment.NewLine;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "\\log\\"));
|
||||
bool writeSuccess = false;
|
||||
int loopInc = 0;
|
||||
while(!writeSuccess)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(Path.Combine(Directory.GetCurrentDirectory(), filePath)))
|
||||
{
|
||||
File.AppendAllText(Path.Combine(Directory.GetCurrentDirectory(), filePath), "Temperature,Humidity" + Environment.NewLine);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
File.AppendAllText(Path.Combine(Directory.GetCurrentDirectory(), filePath), finalString);
|
||||
writeSuccess = true;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
Console.WriteLine("File in use");
|
||||
if(loopInc >10)
|
||||
{
|
||||
throw new IOException("File is in use and could not be unlocked");
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
loopInc++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public bool IsWebRequest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
36
TCPServerLWCore/Properties/AssemblyInfo.cs
Normal file
36
TCPServerLWCore/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TCPServerLWCore")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("TCPServerLWCore")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("739200ea-9900-4dcc-8a72-bbadc9e73a47")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
59
TCPServerLWCore/TCPServerLWCore.csproj
Normal file
59
TCPServerLWCore/TCPServerLWCore.csproj
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>739200ea-9900-4dcc-8a72-bbadc9e73a47</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TCPServerLWCore</RootNamespace>
|
||||
<AssemblyName>TCPServerLWCore</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System"/>
|
||||
|
||||
<Reference Include="System.Core"/>
|
||||
<Reference Include="System.Xml.Linq"/>
|
||||
<Reference Include="System.Data.DataSetExtensions"/>
|
||||
|
||||
|
||||
<Reference Include="Microsoft.CSharp"/>
|
||||
|
||||
<Reference Include="System.Data"/>
|
||||
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
|
||||
</Project>
|
28
ThermalWebServer.sln
Normal file
28
ThermalWebServer.sln
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThermalWebServer", "ThermalWebServer\ThermalWebServer.csproj", "{D8A53F10-F395-4FD7-B626-8AEC0B68DA17}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TCPServerLWCore", "TCPServerLWCore\TCPServerLWCore.csproj", "{739200EA-9900-4DCC-8A72-BBADC9E73A47}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D8A53F10-F395-4FD7-B626-8AEC0B68DA17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D8A53F10-F395-4FD7-B626-8AEC0B68DA17}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D8A53F10-F395-4FD7-B626-8AEC0B68DA17}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D8A53F10-F395-4FD7-B626-8AEC0B68DA17}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{739200EA-9900-4DCC-8A72-BBADC9E73A47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{739200EA-9900-4DCC-8A72-BBADC9E73A47}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{739200EA-9900-4DCC-8A72-BBADC9E73A47}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{739200EA-9900-4DCC-8A72-BBADC9E73A47}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
19
ThermalWebServer/Program.cs
Normal file
19
ThermalWebServer/Program.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using TCPServerLWCore;
|
||||
|
||||
namespace ThermalWebServer
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Server tcpServer = new Server();
|
||||
tcpServer.initServer();
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
36
ThermalWebServer/Properties/AssemblyInfo.cs
Normal file
36
ThermalWebServer/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ThermalWebServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ThermalWebServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d8a53f10-f395-4fd7-b626-8aec0b68da17")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
61
ThermalWebServer/ThermalWebServer.csproj
Normal file
61
ThermalWebServer/ThermalWebServer.csproj
Normal file
@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D8A53F10-F395-4FD7-B626-8AEC0B68DA17}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ThermalWebServer</RootNamespace>
|
||||
<AssemblyName>ThermalWebServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TCPServerLWCore\TCPServerLWCore.csproj">
|
||||
<Project>{739200ea-9900-4dcc-8a72-bbadc9e73a47}</Project>
|
||||
<Name>TCPServerLWCore</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Reference in New Issue
Block a user