public static async Task ReceiveAllPacketsSync(SocketObject client) { bool completePacketReceived = false; // delete any previously recveived complete packet client.packet = ""; // loop through all partial packets to make complete packet while (!completePacketReceived) { Console.WriteLine("Receiving..."); // recv partial packet int recvBytes = await ReceiveTask(client); Console.WriteLine("Received partial packet."); // check if connection is still alive if (recvBytes == -1) { throw new SocketException(); } // add partial packet to string client.packet += Encoding.ASCII.GetString(client.buffer); // check if partial packet made complete packet if (client.buffer[recvBytes - 3] == 126) // packet received = buffer + NULL TERMINATOR (0) + NULL TERMINATOR (0) { completePacketReceived = true; } // reset buffer client.buffer = new byte[SocketObject.BufferSize]; } }
public static Task<bool> ConnectTask(SocketObject client){ return Task.Factory.StartNew(() => { try{ client.socket.Connect(client.iep); }catch (SocketException ex){ Console.WriteLine("Connect() exception triggered: {0}", ex); return false; } return true; }); }
public static Task<int> ReceiveTask(SocketObject client) { return Task.Factory.StartNew(() => { int result = -1; try{ result = client.socket.Receive(client.buffer); }catch (SocketException ex){ Console.WriteLine("Receive() exception triggered: {0}", ex); } return result; }); }
public static Task <int> ReceiveTask(SocketObject client) { return(Task.Factory.StartNew(() => { int result = -1; try{ result = client.socket.Receive(client.buffer); }catch (SocketException ex) { Console.WriteLine("Receive() exception triggered: {0}", ex); } return result; })); }
public static Task <bool> ConnectTask(SocketObject client) { return(Task.Factory.StartNew(() => { try{ client.socket.Connect(client.iep); }catch (SocketException ex) { Console.WriteLine("Connect() exception triggered: {0}", ex); return false; } return true; })); }
public LoginWindow() { InitializeComponent(); rect_window_fadein(); UsernameTextbox.Text = "Username"; PasswordTextbox.Text = "Password"; Username = ""; Password = ""; client = new SocketObject(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), new IPEndPoint(IPAddress.Parse("172.16.1.68"), 11002)); UIGlobal.LoginWindowUI = this; UIGlobal.sharedTCPObject = client; Connect(); }
public static Task<int> SendTask(SocketObject client, byte[] msg) { return Task.Factory.StartNew(() => { int result = -1; try { result = client.socket.Send(msg); Console.WriteLine("Sent: {0}", Encoding.ASCII.GetString(msg)); } catch (SocketException ex) { Console.WriteLine("Send() exception triggered: {0}", ex); } return result; }); }
public static Task <int> SendTask(SocketObject client, byte[] msg) { return(Task.Factory.StartNew(() => { int result = -1; try { result = client.socket.Send(msg); Console.WriteLine("Sent: {0}", Encoding.ASCII.GetString(msg)); } catch (SocketException ex) { Console.WriteLine("Send() exception triggered: {0}", ex); } return result; })); }
public SharedData(string login, AccessLevel accessLevel, SocketObject sock) { _name = login; _accesslevel = accessLevel; _clientObject = sock; }
public DataWindow(SharedData sharedData) { InitializeComponent(); this.DataContext = this; // get data from shared data loginName = sharedData._name; accessLevel = sharedData._accesslevel.ToString(); client = sharedData._clientObject; // set GUI info AccessLevel.Content = "Access level: " + accessLevel; UI_Username.Content = "Logged in as: " + loginName; // set client variables currentPacket = RECEIVED_PACKET_TYPE.DEFAULT; // show GUI showMenuGUI(); // receive async receiveAsync(); }