首页 \ 问答 \ socket API接受()函数如何工作?(How does the socket API accept() function work?)

socket API接受()函数如何工作?(How does the socket API accept() function work?)

套接字API是TCP / IP和UDP / IP通信的实际标准(即我们所知道的网络代码)。 但是,它的一个核心功能是accept()有点神奇。

借用半正式定义:

在服务器端使用accept()。 它接受从远程客户端创建新的TCP连接的接收到的尝试,并创建与此连接的套接字地址对相关联的新套接字。

换句话说, accept返回一个新的套接字,服务器可以通过这个新的套接字与新连接的客户端通信。 在同一个端口上,旧套接字(在其上被称为接受者)保持打开状态,监听新连接。

accept工作怎么办? 如何实施? 这个话题有很多混乱。 许多人声称接受打开一个新的端口,并通过它与客户端进行通信。 但这显然不是真的,因为没有新的港口被打开。 您实际上可以通过与不同客户端的同一个端口进行通信,但是如何? 当几个线程在同一个端口上调用recv时,数据如何知道去哪里?

我猜这是客户端的地址与一个套接字描述符相关的东西,每当数据通过recv它被路由到正确的套接字,但我不确定。

对这种机制的内在作用进行彻底的解释是非常好的。


The socket API is the de-facto standard for TCP/IP and UDP/IP communications (that is, networking code as we know it). However, one of its core functions, accept() is a bit magical.

To borrow a semi-formal definition:

accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.

In other words, accept returns a new socket through which the server can communicate with the newly connected client. The old socket (on which accept was called) stays open, on the same port, listening for new connections.

How does accept work? How is it implemented? There's a lot of confusion on this topic. Many people claim accept opens a new port and you communicate with the client through it. But this obviously isn't true, as no new port is opened. You actually can communicate through the same port with different clients, but how? When several threads call recv on the same port, how does the data know where to go?

I guess it's something along the lines of the client's address being associated with a socket descriptor, and whenever data comes through recv it's routed to the correct socket, but I'm not sure.

It'd be great to get a thorough explanation of the inner-workings of this mechanism.


原文:https://stackoverflow.com/questions/489036
更新时间:2022-09-20 18:09

最满意答案

使用CursorLoaders加载数据并填充ListView。

http://developer.android.com/reference/android/content/CursorLoader.html

然后使用getContext().getContentResolver().notifyChange(resultUri, null); 当您插入,更新或删除!

如果没有CursorLoaders,则必须使用ContentObservers

所以,虽然DB在后台更新,你使用的是notifyChange()但没有人在听!


Use CursorLoaders to load the data and populate the ListView.

http://developer.android.com/reference/android/content/CursorLoader.html

Then use getContext().getContentResolver().notifyChange(resultUri, null); when you insert, update or delete!

Without CursorLoaders you will have to use ContentObservers

So, although DB is updated in background and you are using notifyChange() but no one is listening to that!

相关问答

更多
  • 一个应用实现ContentProvider来提供内容给别的应用来操作, 一个应用通过ContentResolver来操作别的应用数据,当然在自己的应用中也可以。 查看原帖>>
  • 添加一个小的匿名jQuery函数来检查表单的HTML5有效性状态。 (function( $ ){ $.fn.isValid = function() { return checkValidity(); }; })(jQuery); 然后在提交中使用它 $('#submitSearch').on('click', function(e) { if(this.isValid()){ } else { } }); Add a small an ...
  • 使用CursorLoaders加载数据并填充ListView。 http://developer.android.com/reference/android/content/CursorLoader.html 然后使用getContext().getContentResolver().notifyChange(resultUri, null); 当您插入,更新或删除! 如果没有CursorLoaders,则必须使用ContentObservers 所以,虽然DB在后台更新,你使用的是notifyChange ...
  • 您的代码工作正常,除了
    元素没有change事件。 如果你需要在更改div.contentdiv的div.contentdiv时触发一个事件,你最好在你的AJAX方法的success回调中做到这一点(如果你使用jQuery的$.get()或$.ajax()那就非常简单了。 $.ajax() )。 您可能还会考虑查看DOMNodeInserted和DOMNodeRemoved ,但这些是一般的突变事件,可能无法转换为您的要求。 Ben Nadel也在这里发表了类似问题的博客。 Your code is ...
  • 到目前为止,我们通过使用单独的SDK <11,11-18,> = 19的逻辑,通过ContentResolver检索时解决了Cursor == null。 我强烈建议您删除所有代码并正确使用Uri 。 应用程序的流程如下: 你的第3步是毫无意义的。 你知道文件的位置,因为你把它放在第2步中。 并且,通过摆脱步骤#3,您还可以摆脱所有伪造的“真实路径”代码。 有人可以猜到为什么 也许MediaStore不了解图像,因为它还没有编入索引。 请参阅MediaScannerConnection及其scanFile( ...
  • 因为在一般函数中,我们默认引用'窗口'对象,所以我们所做的任何事情都变成窗口级别的对象或变量。 喜欢, function fun(){ this.title = "window"; } fun(); 或window.fun(); //都是一样的。 由于我们调用window.fun,this.title表示window.fun。 如果你这样创建: var obj = {} **现在在obj级别制作标题,你可以这样做: fun.call(obj); 现在你可以调用obj.title。** Because ...
  • 您的代码应如下所示 $('input').keyup( function() { console.log('k'); }); $('input').keyup(debounce(f, 100)); 在您的示例中,您永远不会调用返回的函数,而是始终创建一个新函数。 根据你的评论。 如何在不同的上下文中使用它。 以下示例将foo写入控制台10次,但只会添加一个时间戳。 function debounce(fn, delay) { var timer = null; return functi ...
  • 我解决了 我的活动没有继承FragmentActivity,我的布局没有任何片段,所以它无法工作 - 没有任何注册的ContentObservers。 现在它看起来像这样: 首先,主要活动开始,注册片段布局并在其onCreate方法中启动后台服务: super.onCreate(savedInstanceState); setContentView(R.layout.list); Intent intent = new Intent(this.getApplicationContext(), UsersD ...
  • 通知一次进行批量操作,而不是每次插入的记录一次。 将您的呼叫转移到notifyChange,使其跟随for循环。 Notify once for the bulk operation, not once for each record inserted. Move your call to notifyChange such that it follows the for loop.
  • 你应该做几件事。 而不是 prestige.php?item=&rating= 使用 prestige.php? $article['id'], 'rating' => $x), '&') ?> 这将逃避参数。 Vars $article['id']和$x可能包含破坏HTML或URL的字符。 2.查看Firebug / Chrome开发 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)