Guest User

Untitled

a guest
Jun 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. internal void Initialize(int port,string IP)
  2. {
  3. IPEndPoint _Point = new IPEndPoint(IPAddress.Parse(IP), port);
  4. Socket _Accpt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  5. try
  6. {
  7. _Accpt.Bind(_Point);
  8. }
  9. catch (SocketException exc)
  10. {
  11. System.Windows.Forms.MessageBox.Show(exc.Message);
  12.  
  13. }
  14. finally
  15. {
  16. _Accpt.Listen(2); //Second exception is here after the code continues after the catch block
  17. _Accpt.BeginAccept(null, 0, new AsyncCallback(Accept), _Accpt);
  18. }
  19. }
  20.  
  21. FileStream fs = null;
  22.  
  23. try
  24. {
  25. fs = new FileStream(...)
  26.  
  27. // process the data
  28.  
  29. }
  30. catch (IOException)
  31. {
  32. // inside this catch block is where you put code that recovers
  33. // from an IOException
  34. }
  35. finally
  36. {
  37. // make sure the file gets closed
  38. if (fs != null) fs.Close();
  39. }
  40.  
  41. try
  42. {
  43. _Accpt.Bind(_Point);
  44. _Accpt.Listen(2); //Second exception is here after the code continues after the catch block
  45. _Accpt.BeginAccept(null, 0, new AsyncCallback(Accept), _Accpt);
  46. }
  47. catch (SocketException exc)
  48. {
  49. System.Windows.Forms.MessageBox.Show(exc.Message);
  50.  
  51. }
  52. finally
  53. {
  54. //Final logging
  55. //Disposal of initial objects etc...
  56. }
Add Comment
Please, Sign In to add comment