-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tlhan Ghun <info@tlhan-ghun.de>
- Loading branch information
0 parents
commit 9a0a32e
Showing
1 changed file
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
|
||
namespace FileSystemSnarl.SnarlNetwork | ||
{ | ||
class SnarlNetwork | ||
{ | ||
int response = 0; | ||
|
||
|
||
public SnarlNetwork(string hostName, int hostPort) | ||
{ | ||
|
||
} | ||
|
||
public bool register(string hostName, int hostPort, string appName) | ||
{ | ||
IPAddress host = IPAddress.Parse(hostName); | ||
IPEndPoint hostep = new IPEndPoint(host, hostPort); | ||
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
try | ||
{ | ||
sock.Connect(hostep); | ||
response = sock.Send(Encoding.ASCII.GetBytes("type=SNP#?version=1.0#?action=register#?app=" + appName)); | ||
response = sock.Send(Encoding.ASCII.GetBytes("\r\n")); | ||
sock.Close(); | ||
} | ||
catch (SocketException e) | ||
{ | ||
Console.WriteLine("Problem connecting to host"); | ||
Console.WriteLine(e.ToString()); | ||
sock.Close(); | ||
} | ||
return true; | ||
} | ||
|
||
public bool unregister(string hostName, int hostPort,string appName) | ||
{ | ||
IPAddress host = IPAddress.Parse(hostName); | ||
IPEndPoint hostep = new IPEndPoint(host, hostPort); | ||
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
try | ||
{ | ||
sock.Connect(hostep); | ||
response = sock.Send(Encoding.ASCII.GetBytes("type=SNP#?version=1.0#?action=unregister#?app=" + appName)); | ||
response = sock.Send(Encoding.ASCII.GetBytes("\r\n")); | ||
sock.Close(); | ||
} | ||
catch (SocketException e) | ||
{ | ||
Console.WriteLine("Problem connecting to host"); | ||
Console.WriteLine(e.ToString()); | ||
if (sock.Connected) | ||
{ | ||
sock.Close(); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public bool addClass(string hostName, int hostPort, string appName, string className, string classTitle) | ||
{ | ||
IPAddress host = IPAddress.Parse(hostName); | ||
IPEndPoint hostep = new IPEndPoint(host, hostPort); | ||
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
try | ||
{ | ||
sock.Connect(hostep); | ||
} | ||
catch (SocketException e) | ||
{ | ||
Console.WriteLine("Problem connecting to host"); | ||
Console.WriteLine(e.ToString()); | ||
if (sock.Connected) | ||
{ | ||
sock.Close(); | ||
} | ||
} | ||
try { | ||
response = sock.Send(Encoding.ASCII.GetBytes("type=SNP#?version=1.0#?action=add_class#?app=" + appName + "#?class=" + className + "#?title=" + classTitle)); | ||
response = sock.Send(Encoding.ASCII.GetBytes("\r\n")); | ||
} | ||
catch (SocketException e) | ||
{ | ||
Console.WriteLine(e.ToString()); | ||
} | ||
sock.Close(); | ||
return true; | ||
} | ||
|
||
public bool notify(string hostName, int hostPort, string appName, string className, string title, string text, string timeout) | ||
{ | ||
IPAddress host = IPAddress.Parse(hostName); | ||
IPEndPoint hostep = new IPEndPoint(host, hostPort); | ||
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
try | ||
{ | ||
sock.Connect(hostep); | ||
response = sock.Send(Encoding.ASCII.GetBytes("type=SNP#?version=1.0#?action=notification#?app=" + appName + "#?class=" + className + "#?title=" + title + "#?text=" + text + "#?timeout=" + timeout)); | ||
response = sock.Send(Encoding.ASCII.GetBytes("\r\n")); | ||
sock.Close(); | ||
} | ||
catch (SocketException e) | ||
{ | ||
Console.WriteLine("Problem connecting to host"); | ||
Console.WriteLine(e.ToString()); | ||
if (sock.Connected) | ||
{ | ||
sock.Close(); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} | ||
} |