Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #pragma mark -
  2. #pragma mark Socket Actions
  3.  
  4.  
  5. -(void) connect
  6. {
  7. _socket = [[AsyncSocket alloc] init];
  8. [_socket setDelegate:self];
  9. //[_socket connectToHost:@"localhost" onPort:80 withTimeout:15.0f error:nil];
  10. [_socket connectToHost:[[NSUserDefaults standardUserDefaults] objectForKey:@"ip"] onPort:2001 error:nil];
  11. _connectionStatusLabel.text = NSLocalizedString(@"Waiting for connection",nil);
  12. }
  13. - (IBAction)lcdPressed:(id)sender {
  14. NSString *cmd = @"HITK OK";
  15. [self sendDataToSo
  16.  
  17. -(void)disconnect
  18. {
  19. [_socket disconnect];
  20. [_socket release];
  21. _socket = nil;
  22. }
  23.  
  24. -(void)sendDataToSocket:(NSData*)data {
  25. if (_socket != nil) {
  26. [_socket writeData:data withTimeout:15 tag:1];
  27. }
  28. }
  29.  
  30. #pragma mark -
  31. #pragma mark General Actions
  32.  
  33. -(IBAction) connectButtonPressed:(id)sender {
  34.  
  35. if (_connected) {
  36. [self disconnect];
  37. } else {
  38. [self connect];
  39. }
  40. }
  41.  
  42. - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
  43.  
  44. [self dismissModalViewControllerAnimated:YES];
  45. }
  46.  
  47.  
  48. - (IBAction)showInfo:(id)sender {
  49.  
  50. FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
  51. controller.delegate = self;
  52.  
  53. controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  54. [self presentModalViewController:controller animated:YES];
  55.  
  56. [controller release];
  57. }
  58.  
  59. - (IBAction)pageControlDidChange:(UIPageControl*)sender
  60. {
  61. [_scrollView scrollRectToVisible:CGRectMake(sender.currentPage*_scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height) animated:YES];
  62.  
  63. }
  64.  
  65. #pragma mark -
  66. #pragma mark Sender Actions
  67. #pragma mark -
  68. #pragma mark Socket Delegates
  69.  
  70. - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
  71. _connectionStatusLabel.text = NSLocalizedString(@"Connection established",nil);
  72. _connected = YES;
  73. [_connectButton setTitle:NSLocalizedString(@"Disconnect",nil) forState:UIControlStateNormal];
  74. }
  75.  
  76. - (void)onSocketDidDisconnect:(AsyncSocket *)sock {
  77. _connectionStatusLabel.text = NSLocalizedString(@"Not connected",nil);
  78. _connected = NO;
  79. [_connectButton setTitle:NSLocalizedString(@"Connect",nil) forState:UIControlStateNormal];
  80.  
  81. }
  82.  
  83. #pragma mark -
  84. #pragma mark UIScrollView delegate
  85.  
  86. - (void)scrollViewDidEndDecelerating:(UIScrollView *)aScrollView
  87. {
  88. _pageControl.currentPage = _scrollView.contentOffset.x / _scrollView.frame.size.width;
  89. if (_pageControl.currentPage == 2) {
  90. [_commandTextField becomeFirstResponder];
  91. } else {
  92. [_commandTextField resignFirstResponder];
  93. }
  94.  
  95. }
  96.  
  97. #pragma mark -
  98. #pragma mark TextField delegate
  99.  
  100. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  101. {
  102. [textField resignFirstResponder];
  103. NSString *cmd = textField.text;
  104. [self sendDataToSocket:[cmd dataUsingEncoding:NSUTF8StringEncoding]];
  105. return YES;
  106. }
  107.  
  108. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
  109. {
  110. return YES;
  111. }
  112.  
  113.  
  114. #pragma mark -
  115. #pragma mark Memory Management
  116.  
  117. - (void)didReceiveMemoryWarning {
  118. // Releases the view if it doesn't have a superview.
  119. [super didReceiveMemoryWarning];
  120.  
  121. // Release any cached data, images, etc. that aren't in use.
  122. }
  123.  
  124.  
  125. - (void)viewDidUnload {
  126. // Release any retained subviews of the main view.
  127. // e.g. self.myOutlet = nil;
  128. }
  129.  
  130.  
  131. - (void)dealloc {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement