无法处理此断开事件,不知道为什么socket不发送给客户端/客户端没有响应!
服务器
io.sockets.on('connection', function (socket) {
socket.on('NewPlayer', function(data1) {
online = online + 1;
console.log('Online players : ' + online);
console.log('New player connected : ' + data1);
Players[data1] = data1;
console.log(Players);
});
socket.on('DelPlayer', function(data) {
delete Players[data];
console.log(Players);
console.log('Adios' + data);
});
socket.on('disconnect', function () {
socket.emit('disconnected');
online = online - 1;
});
});
Run Code Online (Sandbox Code Playgroud)
客户
var socket = io.connect('http://localhost');
socket.on('connect', function () {
person_name = prompt("Welcome. Please enter your name");
socket.emit('NewPlayer', person_name);
socket.on('disconnected', function() {
socket.emit('DelPlayer', person_name);
});
});
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,当客户端断开连接时,应该删除数组对象[person_name],但不是
几天前我开始使用laravel,我正面临这个问题:
将NO永远不会回来了!
这是Controller,你知道为什么吗?
Class TestController extends BaseController {
public function __construct()
{
if (!Auth::check()) return 'NO';
}
public function test($id)
{
return $id;
}
}
Run Code Online (Sandbox Code Playgroud) 目前我有类似的东西
main.go
gojob.NewJob("every 2 second", "pene", func() {
t := gojob.Custom("pene")
log.Println(t)
}, struct {
Id int
}{
1,
})
Run Code Online (Sandbox Code Playgroud)
我的gojob包
func NewJob(t string, name string, c func(), v interface{}) {
e := strings.Split(t, " ")
job := process(e)
job.log = false
job.name = name
job.action = c
job.custom = v
jobs = append(jobs, job)
}
Run Code Online (Sandbox Code Playgroud)
和
func Custom(name string) interface{} {
for i := range jobs {
if jobs[i].name != name {
continue
}
return jobs[i].custom
}
return nil …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试在Go项目中添加一些C代码.没有什么花哨
/*
#include <stdio.h>
void test() {
printf("hooola")
}
*/
import (
"C"
)
func MessageBox() {
C.test()
}
Run Code Online (Sandbox Code Playgroud)
然而,这将返回
cc1.exe:抱歉,未实现:64位模式未编译
我检查了我g++和gcc编译器,一切似乎都很好,g++ -v返回此
C:\Users\ragga>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=C:/Program\ Files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/6.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-6.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw620/x86_64-620-posix-seh-rt_v5-rev1/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --enable-libstdcxx-filesystem-ts=yes --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw620/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw620/prerequisites/x86_64-w64-mingw32-static …Run Code Online (Sandbox Code Playgroud) 我使用以下代码
List<String> text = new ArrayList<String>();
text.add("Hello");
Run Code Online (Sandbox Code Playgroud)
所以该列表只接受要添加的字符串,如何将更多类型的变量(如整数和字符串)添加到一个列表中
在文本列表中添加一些矩形值,如
矩形名称,矩形宽度,矩形高度
所以后来我可以循环访问它们
我正在尝试绘制多个透明图像以形成一个大图像并将其另存为PNG
func generateUserImage(username string, items []models.Item) error {
imageFile, err := os.Create("public/items/users/" + username + ".png")
if err != nil {
return err
}
profileImage := image.NewRGBA(image.Rect(0, 0, 261, 336))
for _, item := range items {
revel.INFO.Println(item)
itemFile, err := os.Open("public/items/universe/" + item.Type + "/" + item.Name + ".png")
if err != nil {
return err
}
itemImage, err := png.Decode(itemFile)
if err != nil {
return err
}
draw.Draw(profileImage, profileImage.Bounds(), itemImage, image.Point{0, 0}, draw.Src)
itemFile.Close()
}
err = …Run Code Online (Sandbox Code Playgroud) 我试图使用通道捕获一组 goroutine 中的错误,但通道进入无限循环,开始消耗 CPU。
func UnzipFile(f *bytes.Buffer, location string) error {
zipReader, err := zip.NewReader(bytes.NewReader(f.Bytes()), int64(f.Len()))
if err != nil {
return err
}
if err := os.MkdirAll(location, os.ModePerm); err != nil {
return err
}
errorChannel := make(chan error)
errorList := []error{}
go errorChannelWatch(errorChannel, errorList)
fileWaitGroup := &sync.WaitGroup{}
for _, file := range zipReader.File {
fileWaitGroup.Add(1)
go writeZipFileToLocal(file, location, errorChannel, fileWaitGroup)
}
fileWaitGroup.Wait()
close(errorChannel)
log.Println(errorList)
return nil
}
func errorChannelWatch(ch chan error, list []error) {
for {
select { …Run Code Online (Sandbox Code Playgroud) 我正在学习Java,我现在面临以下错误
Object label1 = addLabel("First number");
Run Code Online (Sandbox Code Playgroud)
还有我的addLabel功能
public Object addLabel(String text)
{
JLabel label = new JLabel(text);
add(label);
return label;
}
Run Code Online (Sandbox Code Playgroud)
我想知道为什么我不能在我的变量label1上访问任何标签方法,如果我将它作为对象返回?
例如: label1.setBounds(...);
我有这个字符串数组:
array(59) {
[0]=> string(25) "shadowcores.twifysoft.net"
[1]=> string(11) " "
}
Run Code Online (Sandbox Code Playgroud)
显然,还有57个元素.我需要知道如何删除它:
string(11) " "
Run Code Online (Sandbox Code Playgroud)
没有要显示的字符串,但字符串本身并非空.在将它们添加到数组之前,如何检查这些类型的值?
我目前的代码看起来像这样
this.actHandler = new MainAct(reqParams[2], new DatabaseHandler());
RegisterAct regAct = new RegisterAct();
return regAct.RegisterAction();
Run Code Online (Sandbox Code Playgroud)
MainAct类
class MainAct
{
protected DatabaseHandler dbh;
protected MySqlConnection db;
protected MySqlDataReader reader;
protected MySqlCommand cmd;
protected string param;
public MainAct(string param, DatabaseHandler dbHandler)
{
this.param = param;
this.dbh = dbHandler;
this.db = this.dbh.ConnectDatabase();
}
}
Run Code Online (Sandbox Code Playgroud)
RegisterAct类
class RegisterAct : MainAct
{
public string RegisterAction()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:
BloodServer.act.MainAct不包含带有0参数的构造函数
这是在Parent类中,我认为我已经替换了它.
Parent构造函数是否仍然被调用?有没有办法改变这个?