Quelques fix sur le code du serveur
This commit is contained in:
parent
623d5c307c
commit
c17ccbfb71
@ -1,6 +1,9 @@
|
|||||||
package com.bernard.murder;
|
package com.bernard.murder;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.stream.Stream.Builder;
|
||||||
|
|
||||||
public class BytesUtils {
|
public class BytesUtils {
|
||||||
|
|
||||||
@ -17,4 +20,17 @@ public class BytesUtils {
|
|||||||
buffer.put(data);
|
buffer.put(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Stream<Byte> toStream(ByteBuffer buffer){
|
||||||
|
Builder<Byte> bldr = Stream.builder();
|
||||||
|
|
||||||
|
for(Byte b: buffer.array())
|
||||||
|
bldr.add(b);
|
||||||
|
|
||||||
|
return bldr.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void dump(ByteBuffer buffer) {
|
||||||
|
System.out.println(toStream(buffer).limit(buffer.position()).map(b -> b.toString()).collect(Collectors.joining(",")));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -112,6 +112,7 @@ public class AudioServer {
|
|||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
System.out.println("Accepting request from "+senderAddress);
|
||||||
break;
|
break;
|
||||||
case AudioServer.ASK_STREAMING:
|
case AudioServer.ASK_STREAMING:
|
||||||
int listened = data.getInt();
|
int listened = data.getInt();
|
||||||
@ -163,10 +164,12 @@ public class AudioServer {
|
|||||||
ByteBuffer out2 = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
ByteBuffer out2 = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
||||||
out2.put(AudioServer.GIVE_AUDIO_LIST);
|
out2.put(AudioServer.GIVE_AUDIO_LIST);
|
||||||
out2.putInt(mics.size());
|
out2.putInt(mics.size());
|
||||||
for(Entry<Integer, String> e : mics.entrySet()) {
|
for(Entry<Integer, String> mic : mics.entrySet()) {
|
||||||
out2.putInt(e.getKey());
|
out2.putInt(mic.getKey());
|
||||||
BytesUtils.writeString(out2, e.getValue());
|
BytesUtils.writeString(out2, mic.getValue());
|
||||||
}
|
}
|
||||||
|
System.out.println("Sending audio list to "+senderAddress+" : ");
|
||||||
|
BytesUtils.dump(out2);
|
||||||
try {
|
try {
|
||||||
serveur.sendData(out2, senderAddress);
|
serveur.sendData(out2, senderAddress);
|
||||||
} catch (IOException e1) {
|
} catch (IOException e1) {
|
||||||
|
|||||||
@ -103,7 +103,7 @@ public class MicServer {
|
|||||||
|
|
||||||
micId = deviceId;
|
micId = deviceId;
|
||||||
|
|
||||||
serverAnswered.run();
|
new Thread(serverAnswered).start();
|
||||||
|
|
||||||
if(micLine==null)
|
if(micLine==null)
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -112,6 +112,7 @@ public class Serveur {
|
|||||||
public void sendData(byte[] data, SocketAddress address) throws IOException {
|
public void sendData(byte[] data, SocketAddress address) throws IOException {
|
||||||
if(data.length < packetMaxLength) {
|
if(data.length < packetMaxLength) {
|
||||||
DatagramPacket packet = new DatagramPacket(data, data.length,address);
|
DatagramPacket packet = new DatagramPacket(data, data.length,address);
|
||||||
|
System.out.println("Sent "+packet.getLength()+" bytes to "+packet.getAddress());
|
||||||
socket.send(packet);
|
socket.send(packet);
|
||||||
}else {
|
}else {
|
||||||
short packetCount = (short) (data.length / (packetMaxLength-42));
|
short packetCount = (short) (data.length / (packetMaxLength-42));
|
||||||
|
|||||||
@ -130,7 +130,7 @@ public class SpeakerServer {
|
|||||||
if(!isMicListUpToDate)askAudioList();
|
if(!isMicListUpToDate)askAudioList();
|
||||||
while(!isMicListUpToDate) {
|
while(!isMicListUpToDate) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);//XXX Can be interrupted here avec le bouton «Arreter»
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ public class SpeakerServer {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
speakerId = deviceId;
|
speakerId = deviceId;
|
||||||
serverAnswered.run();
|
new Thread(serverAnswered).start();
|
||||||
if(speakerLine==null)
|
if(speakerLine==null)
|
||||||
try {
|
try {
|
||||||
initializeSpeakerDevice();
|
initializeSpeakerDevice();
|
||||||
@ -177,6 +177,7 @@ public class SpeakerServer {
|
|||||||
int thisMicId = data.getInt();
|
int thisMicId = data.getInt();
|
||||||
mics.put(thisMicId,BytesUtils.readString(data));
|
mics.put(thisMicId,BytesUtils.readString(data));
|
||||||
}
|
}
|
||||||
|
System.out.println("Audio list given: "+mics);
|
||||||
isMicListUpToDate=true;
|
isMicListUpToDate=true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@ -69,14 +69,12 @@ public class GameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void quickSave() {
|
public void quickSave() {
|
||||||
System.out.println("Quicksaving");
|
|
||||||
File toSave = new File(quickSaveFilename());
|
File toSave = new File(quickSaveFilename());
|
||||||
File tempOldSave = new File(quickSaveFilename()+".tmp");
|
File tempOldSave = new File(quickSaveFilename()+".tmp");
|
||||||
if(toSave.exists())toSave.renameTo(tempOldSave);
|
if(toSave.exists())toSave.renameTo(tempOldSave);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GameCreator.quickSave(toSave, partie,minelsQuicksaver.get());
|
GameCreator.quickSave(toSave, partie,minelsQuicksaver.get());
|
||||||
System.out.println("Quicksaved");
|
|
||||||
if(tempOldSave.exists())tempOldSave.delete();
|
if(tempOldSave.exists())tempOldSave.delete();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@ -73,6 +73,7 @@ public class EnceinteServeurFrame extends JFrame{
|
|||||||
NamedMicrophone[] micarray = new NamedMicrophone[list.size()];
|
NamedMicrophone[] micarray = new NamedMicrophone[list.size()];
|
||||||
list.toArray(micarray);
|
list.toArray(micarray);
|
||||||
mics.setListData(micarray);
|
mics.setListData(micarray);
|
||||||
|
System.out.println("Micros chargés: "+list);
|
||||||
});
|
});
|
||||||
serverControl.setText("Lancement");
|
serverControl.setText("Lancement");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user