D
D
Dmitry Richter2014-05-03 23:28:49
C++ / C#
Dmitry Richter, 2014-05-03 23:28:49

C++.Working with sockets?

I do everything as it should be, I open a socket on the client and the server .. it comes to the moment when the server application should listen to the client (I use the recv function for this), the problem is that I threw it into the timer and when it has to execute it, it hangs stupidly and I’m waiting for something to come, I’m racking my brains, I don’t know how to solve this problem correctly, I’m already tired of looking in Google.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Deerenaros, 2014-05-04
@followthemoney

And what kind of implementation and what API? Trite because C++ by default (standard) can't work with sockets. Especially when you consider some differences in their (sockets) implementations on different platforms (being POSIX on unixes, POSIX-like on linuxes, and something funny on both Windows and kolibri OS. In general, Berkeley sockets should help, In general, it's a thankless task to use sockets from C++ outside of frameworks.Better than C#.NET, Java, Python: everything is for people here.Well, if pluses in C are important, then you can use the incredible Qt.

J
jcmvbkbc, 2014-05-04
@jcmvbkbc

Google select, fcntl and O_NONBLOCK.

B
bogolt, 2014-05-04
@bogolt

By default, all socket operations are blocking. This means that until the operation is completed, the code will not go further.
There are many methods for solving this problem:
- use non-blocking sockets
- use a non-blocking select call
- allocate everything to a separate thread (a bad method, then you are tormented to figure out why it crashes).
I advise you to read the network programming manual, or at least look at the client and server code. beej.us/guide/bgnet/output/html/multipage/index.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question