private void p_UserChannelCreated(object sender, ChannelCreatedEventArgs e) { e.CanDisposeChannel = false; SendFileInfo info = (SendFileInfo)e.Data; ServerClient otherClient; lock (fClients) fClients.TryGetValue(info.To, out otherClient); if (otherClient == null) { return; } var otherRemotingClient = RemotingClient.GetFromRemoteObject(otherClient.fClient); using (var otherChannel = otherRemotingClient.CreateUserChannel(info)) { UnlimitedThreadPool.Run ( delegate { try { while (true) { int b = otherChannel.ReadByte(); if (b == -1) { e.Channel.Dispose(); return; } e.Channel.WriteByte((byte)b); e.Channel.Flush(); } } catch { otherChannel.Dispose(); e.Channel.Dispose(); } } ); byte[] buffer = new byte[8 * 1024]; while (true) { int read = e.Channel.Read(buffer, 0, buffer.Length); if (read <= 0) { return; } otherChannel.Write(buffer, 0, read); otherChannel.Flush(); } } }
protected override void OnShown(EventArgs e) { base.OnShown(e); if (fMustSend) { UnlimitedThreadPool.Run(p_Send); } else { UnlimitedThreadPool.Run(p_Receive); } }
private void p_Initialize(string user, string displayName, string monikerName, IFastEnumerator <byte[]> enumerator) { ClientSize = new Size(160, 120); DisplayName = displayName; MonikerName = monikerName; fUser = user; fEnumerator = enumerator; Text = user; FormMain.fActiveWebCams.Add(new KeyValuePair <string, string>(fUser, MonikerName), this); Disposed += p_Disposed; UnlimitedThreadPool.Run(p_Receive); }
public FakeWebCamEnumerator(Color backgroundColor) { BackgroundColor = backgroundColor; UnlimitedThreadPool.Run ( () => { while (true) { var image = fImage; if (fImage == null) { return; } fCount++; using (var font = new Font(FontFamily.GenericSerif, 26, FontStyle.Bold)) { using (var graphics = Graphics.FromImage(image)) { graphics.Clear(BackgroundColor); graphics.DrawString(fCount.ToString(), font, Brushes.Red, 0, 0); } } using (var stream = new MemoryStream()) { image.Save(stream, ImageFormat.Jpeg); ActualValue = stream.ToArray(); } // 30 frames per second. Thread.Sleep(1000 / 30); } } ); }
public Server() { fServer = new RemotingServer(); fServer.RegisterStaticMethod("GetServer", typeof(Server).GetMethod("GetInstance")); fServer.CryptographyMode = CryptographyMode.Required; fServer.RegisterAcceptedCryptography <RijndaelManaged>(); fServer.MustUseAsyncVoidCalls = true; fServer.UserChannelCreated += p_UserChannelCreated; UnlimitedThreadPool.Run ( delegate { try { fServer.Run(570); } catch { } } ); }
private void receiveSoundCaptureToolStripMenuItem_Click(object sender, EventArgs e) { var selectedItem = listUsers.SelectedItem; if (selectedItem == null) { return; } string selectedUser = selectedItem.ToString(); int pos = selectedUser.LastIndexOf(" - "); if (pos > 0) { selectedUser = selectedUser.Substring(0, pos); } lock (fWaveOutsByClient) { var fastEnumerator = fWaveOutsByClient.GetValueOrDefault(selectedUser); if (fastEnumerator != null) { fastEnumerator.Dispose(); fWaveOutsByClient.Remove(selectedUser); return; } try { if (selectedUser == fNickName) { fastEnumerator = SoundEnumerator.Distributor.CreateClient(); } else { fastEnumerator = fClient.ReceiveSound(selectedUser); } if (fastEnumerator == null) { return; } var outDevices = WaveOut.Devices; if (outDevices.Length == 0) { MessageBox.Show("There are no output sound devices installed."); return; } var outDevice = outDevices[0]; var waveOut = new WaveOut(outDevice, 8000, 16, 1); fWaveOutsByClient.Add(selectedUser, fastEnumerator); UnlimitedThreadPool.Run ( () => { try { while (true) { byte[] buffer = fastEnumerator.GetNext(); if (buffer == null) { return; } waveOut.Play(buffer, 0, buffer.Length); } } catch { } } ); } catch { if (fastEnumerator != null) { try { fastEnumerator.Dispose(); } catch { } } } return; } }