久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何通過 Java 套接字以二進(jìn)制形式發(fā)送數(shù)據(jù)?

How can I send data in binary form over a Java socket?(如何通過 Java 套接字以二進(jìn)制形式發(fā)送數(shù)據(jù)?)
本文介紹了如何通過 Java 套接字以二進(jìn)制形式發(fā)送數(shù)據(jù)?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我見過很多通過 Java 套接字發(fā)送序列化數(shù)據(jù)的示例,但我只想發(fā)送一些簡單的整數(shù)和字符串.而且,問題是我正在嘗試將這些信息傳達(dá)給用 C 編寫的二進(jìn)制文件.

I've seen lots of examples of sending serialized data over sockets in Java, but all I want is to send some simple integers and a string. And, the problem is I'm trying to communicate these to a binary written in C.

那么,底線是:我怎樣才能在 Java 中通過套接字發(fā)送一些字節(jié)?

So, bottom line: how can I just send some bytes over a socket in Java?

推薦答案

我真的不建議直接使用 Java Sockets 庫.我發(fā)現(xiàn) Netty(來自 JBoss)非常容易實(shí)現(xiàn)并且非常強(qiáng)大.Netty ChannelBuffer 類提供了許多用于編寫不同數(shù)據(jù)類型的選項(xiàng),當(dāng)然,如果您愿意,還可以編寫自己的編碼器和解碼器來將 POJO 寫入流中.

I would really recommend not using the Java Sockets library directly. I've found Netty (from JBoss) to be really easy to implement and really powerful. The Netty ChannelBuffer class comes with a whole host of options for writing different data types and of course to can write your own encoders and decoders to write POJOs down the stream if you wish.

這個(gè)頁面是一個(gè)非常好的入門 - 我能夠在 30 分鐘內(nèi)使用自定義編碼器和解碼器制作一個(gè)相當(dāng)復(fù)雜的客戶端/服務(wù)器:http://docs.jboss.org/netty/3.2/guide/html/start.html.

This page is a really good starter - I was able to make a fairly sophisticated client/server with custom encoders and decoders in under 30 minutes reading this: http://docs.jboss.org/netty/3.2/guide/html/start.html.

如果你真的想使用 Java 套接字.套接字輸出流可以包裝在 DataOutputStream 中,它還允許您編寫許多不同的數(shù)據(jù)類型,例如:

If you really want to use Java sockets. The socket output stream can be wrapped in a DataOutputStream which allows you to write many different data types as well, for example:

new DataOutputStream(socket.getOutputStream()).writeInt(5);

希望對你有用.

這篇關(guān)于如何通過 Java 套接字以二進(jìn)制形式發(fā)送數(shù)據(jù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩免费一区 | 我想看国产一级毛片 | 国产乱码精品一区二区三区中文 | 久久一区精品 | 青青草一区二区 | 男人天堂网址 | av在线一区二区三区 | 亚洲天天干 | 国产ts人妖系列高潮 | 国产小视频在线 | 毛色毛片免费看 | 欧美综合国产精品久久丁香 | 99国内精品久久久久久久 | 国产乱码精品一区二区三区五月婷 | 欧美日韩在线一区二区 | 久久天堂网 | 亚洲精品一区二区三区在线 | 日韩精品一二三区 | 日日日日日日bbbbb视频 | 久久久久久毛片免费观看 | 中文字幕精品一区久久久久 | 久久亚洲精品国产精品紫薇 | 亚洲 欧美 综合 | 成人免费视频观看视频 | 亚洲精品日本 | 欧美精品久久 | 免费在线成人 | 亚洲一区二区视频 | 久久99国产精品久久99果冻传媒 | 日本一卡精品视频免费 | 人人干人人干人人 | 在线国产一区 | 成人久久视频 | 日韩伦理一区二区三区 | 亚洲成av人影片在线观看 | 欧美大片一区 | 国产在线区| 亚洲精品视频免费观看 | 亚洲精精品 | 亚洲精品一区av在线播放 | 国产在线观看一区二区三区 |