PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 31, 2022

[FIXED] How I can check if it something available in socket?

 October 31, 2022     c, connect, eof, read-write, sockets     No comments   

Issue

I write a simple application that provide connection between two computers in C. I have a problem with simultaneously reading and writing in socket. I am able to check if user press any key by getch(), but I don't know how to check if it something in socket buffer. When I use read() function it wait until be something in socket. I wanted to check socket buffer and then use read(), but I can't find any function/flag to check this. Maybe is different solution for this problem, perhaps use another thread to read?


Solution

You can use sys/ioctl.h file's method ioctl:

#include <sys/ioctl.h>

...

int count;
ioctl(fd, FIONREAD, &count);

Reference credit : This Answer



Answered By - Kushal
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing