通过套接字java发送字节数组而不发送长度(Sending byte array through socket java without sending length)
我有一个问题。 我想通过套接字发送一个字节数组,但我不想发送它的长度。 我是从服务器端读取的吗?
我尝试过这样的事情:
dos = new DataOutputStream(socket.getOutputStream); dos.write(myByteArray);
并在服务器端
byte data = new data[100]; dis.read(data);
但是这样,我读了100个字节或者没有字节。 我可以读取确切的号码。 我发送的字节数? 谢谢
I hava a question. I want to send an array of bytes through a socket but I don't want to send the length of it. Cand I read it from a server side?
I've tried something like this:
dos = new DataOutputStream(socket.getOutputStream); dos.write(myByteArray);
and on the server side
byte data = new data[100]; dis.read(data);
but in this way, I read 100 bytes or another no of bytes. Can I read exacty the no. of bytes I send? Thanks
原文:https://stackoverflow.com/questions/34267523
最满意答案
你没有做任何事情告诉Django这些表格是分开的。 他们俩都只有一个
name
字段; 什么都没有告诉他们分开。一个简单的解决方案是将
prefix
参数用于表单实例化,以便Django使字段唯一。if request.is_ajax(): form1 = NewCategory(request.POST or None, prefix='form1') if form1.is_valid(): ... else: form1 = NewCategory(prefix='form1') if request.is_ajax(): form2 = NewServiceIn(request.POST or None, prefix='form2') if form2.is_valid(): ... else: form2 = NewServiceIn(prefix='form2')
You haven't done anything to tell Django that the forms are separate. They both only have a
name
field; there is nothing at all to tell them apart.A simple solution for this would be to to use the
prefix
parameter to the forms instantiations, so that Django makes the fields unique.if request.is_ajax(): form1 = NewCategory(request.POST or None, prefix='form1') if form1.is_valid(): ... else: form1 = NewCategory(prefix='form1') if request.is_ajax(): form2 = NewServiceIn(request.POST or None, prefix='form2') if form2.is_valid(): ... else: form2 = NewServiceIn(prefix='form2')
相关问答
更多-
通过本地客户端程序获取服务器mysql数据库信息[2023-04-27]
ajax -
你没有做任何事情告诉Django这些表格是分开的。 他们俩都只有一个name字段; 什么都没有告诉他们分开。 一个简单的解决方案是将prefix参数用于表单实例化,以便Django使字段唯一。 if request.is_ajax(): form1 = NewCategory(request.POST or None, prefix='form1') if form1.is_valid(): ... else: form1 = NewCategory(prefix=' ...
-
如果项目存在,您可以检查for_sale_detail并返回HttpResponseNotFound或者如果没有则返回Http404异常 。 You can check on for_sale_detail if the item exists and return HttpResponseNotFound or raise Http404 exception if not.
-
你可以试试这个。 from django.http import HttpResponse from django.template.loader import render_to_string def search_query(request): var_1 = Products.objects.all() var_2 = request.GET.get("q") if var_2: items = items.filter( Q(First__ ...
-
Ajax调用Django函数(Ajax call to Django function)[2023-05-15]
获得要删除的图像列表后,将其传递给将由Django视图处理的Ajax调用,如下所示: function submitData(data) { var csrftoken = getCookie('csrftoken'); // from https://docs.djangoproject.com/en/1.7/ref/contrib/csrf/#ajax $.ajax({ type: 'POST', beforeSend: function(xhr, se ... -
如果您打算通过Ajax返回JavaScript可用于更新DOM的响应,则需要返回一个HttpResponse ,最好使用JSON格式,可以在您的$ .ajax调用中将其传递给处理程序。 例: import json from django.contrib.auth.models import User from django.http import HttpResponse from django.shortcuts import render def index(request): if r ...
-
Django中的Ajax调用(Ajax Call in Django)[2023-11-26]
回答第一条评论中提出的问题,如果你有 Django中的django.template.context_processors.request > = 1.8 Django中的django.core.context_processors.request <1.8 将上下文预处理器添加到TEMPLATE_CONTEXT_PROCESSORS设置,然后您可以通过{{ request.resolver_match.app_name }}访问模板中当前应用的名称。 您可以通过上下文提供model_name ,如果您不使 ... -
这里有几个明显的错误。 首先,你张贴到“/ ajax_demo /”,但你没有作为一个URL; 只有“/ demo /”。 您确实要更改网址格式或您要发布的网址。 其次,您错误地包含了应用程序模式; 不得使用包含“$”的终端。 它应该是: url(r'^$', include( 'app.urls', namespace = "mainPage")), 第三,你没有在你的请求中包含任何数据。 你需要一个data密钥: $ .ajax({url:'/ demo /',输入:'get',data:{“clus ...
-
我想我在这里找到了答案: 从远程访问localhost上的站点 显然,在没有安全问题的情况下,无法从其他网络访问本地主机。 I think I found the answer here: Access to a site on localhost from remote Apparently local host cannot be accessed from another network without security issues.
-
您可以尝试在ajax调用中检查响应文本: $('.delete').click(function(){ url_delete = 'my-url.com; $.ajax({ type: 'GET', url: url_delete, data:$(".delete_reserv").serialize(), success:function(data) { if(data == 'removed') { ...